Hi. Someone asked me the other day how they could determine the environment's tenant using x++, and here it is. There's a few other fields in the mix, but aadResponse.TenantId in the code below is what you're looking for:
using Microsoft.Dynamics.AX.Security.MicrosoftGraphHelper;
class Class1
{
static void main (Args args)
{
boolean status = false;
str exMessage, failureMessage, response, tenant, s2sCertThumbprint, stackTrace;
// Try to authenticate to AAD
var aadResponse = AADAuthentication::AuthenticateWithAADByCertificate();
status = aadResponse.Status;
tenant = aadResponse.TenantId;
response = aadResponse.Response;
s2sCertThumbprint = aadResponse.S2SCertThumbprint;
stackTrace = aadResponse.StackTrace;
}
}