Tuesday, May 12, 2020

Get List of Model Metadata objects X++ D365FO

class GetListOfMetdataObjectByModelName
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory metadataProviderFactory =
            new Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory();
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();
        str packageDir = environment.get_Aos().get_PackageDirectory();
        Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration diskProviderConfiguration =
            new Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration();
        diskProviderConfiguration.AddMetadataPath(packageDir);
        Microsoft.Dynamics.AX.Metadata.Providers.IMetadataProvider provider =
            metadataProviderFactory.CreateDiskProvider(diskProviderConfiguration);

        str modelName = 'DEVTESTMODEL';

        //Code is to extract is For TableExtensions

        //Change code - Provider.Table
        var TableExtensions = provider.TableExtensions.ListObjectsWithModificationInfo(modelName);
        var TableExtensionsEnumerator = TableExtensions.getEnumerator();
        while(TableExtensionsEnumerator.moveNext())
        {
            var curVal = TableExtensionsEnumerator.get_current();
            var metadataName = strRem(subStr(curVal.ToString(), 2, strFind(curVal.ToString(), ",", 1, strLen(curVal.ToString()))), ",");
            info(strFmt("%1 - TableExtensions - %2",modelName, metadataName));
        }
    }

}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...