Monday, September 25, 2023

X++ code to get metadata of data entities

var entityNames = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityViewNames();

Var enumerator = entityNames.getEnumerator();

while (enumerator.MoveNext())

{
	enumerator.MoveNext();

	Microsoft.Dynamics.AX.Metadata.MetaModel.AxDataEntityView DataEntity = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityView(enumerator.Current);

   if (DataEntity)
   {         

		info(strFmt("Entity Name: %1 -- Entity Label; %2 -- Entity public collection Name: %3 -- Entity Public Name %4 -- Is Entity Public - %5--Is Entity Shared - %6",

		DataEntity.Name,
		SysLabel::labelId2String(DataEntity.Label),
		DataEntity.PublicCollectionName,
		DataEntity.PublicEntityName,
		DataEntity.IsPublic,
		DataEntity.PrimaryCompanyContext));
     }
}

Get D365Fo Host name

using Microsoft.Dynamics.ApplicationPlatform.Environment;
public str GetInfrastructureHost()
{
        IApplicationEnvironment env = EnvironmentFactory::GetApplicationEnvironment();
        str hostUrl = env.Infrastructure.HostUrl;
        
        // Trim https://
        hostUrl = subStr(hostUrl, 9, strLen(hostUrl) - 8);

        return subStr(hostUrl, 1, strFind(hostUrl, '.', 1, strLen(hostUrl)) - 1);
}

Table browser URL in D365FO

Critical Thinking icon icon by Icons8