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));
        }
    }

}

Get Model list with versions & Application & Platform Version X++ D365FO

class GetModelListCls
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        str60                   moduleName;
        CLRObject               moduleModels, sanModels;
        CLRObject               modelEnumerator, sanEnumerator;
        str60                   moduleVersion;

        Microsoft.Dynamics.AX.Metadata.MetaModel.ModelInfo modelInfo;

        moduleModels = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetInstalledModuleNames();
        modelEnumerator = moduleModels.GetEnumerator();
        
        while (modelEnumerator.moveNext())
        {
            moduleName = modelEnumerator.get_Current();
            sanModels = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetModelsInModuleSortedByDisplayName(moduleName);
            sanEnumerator = sanModels.GetEnumerator();
            sanEnumerator.MoveNext();
            modelInfo = sanEnumerator.get_Current();

            moduleVersion = strfmt("%1.%2.%3.%4",
                                        modelInfo.VersionMajor,
                                        modelInfo.VersionMinor,
                                        modelInfo.VersionBuild,
                                        modelInfo.VersionRevision);
            // modelInfo.Layer // Filter based on layers - ISV layer 8
            info(strFmt("%1 - %2 - %3",modelInfo.Module, moduleVersion,modelInfo.Publisher));
        }

        Microsoft.Dynamics.BusinessPlatform.ProductInformation.Provider.ProductInfoProvider provider = Microsoft.Dynamics.BusinessPlatform.ProductInformation.Provider.ProductInfoProvider::get_Provider();
        info(strFmt("Application version: %1",provider.ApplicationVersion));
        info(strFmt("Platform version: %1  ( %2 )",provider.ApplicationVersion,provider.get_PlatformBuildVersion()));
    }

}

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...