6) Environment Hot-Fixes List Using X++ D365FO

Environment Hot-Fixes List Using X++ D365FO & AX 7 


We All knows that information about metadata hotfixes installed directly from Visual Studio and we can check them Using Apply Hotfix Addins(Dynamics 365 -> Addins -> Apply Hotfix).








The same things we can retrieve using X++ Job

Result





Code Sample


class SLD_DemoClass
{

        public static void main(Args _args)
    {
        new SLD_DemoClass().processExecution();

    }

    public void processExecution()
    {
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();

        Microsoft.Dynamics.AX.Metadata.Providers.IMetadataProvider metadataProvider =
            this.getDiskMetadataProvider(environment);


        Microsoft.Dynamics.AX.Metadata.Providers.IMetaUpdateProvider updateProvider = metadataProvider.get_Updates();

        var moduleInfoList = metadataProvider.ModelManifest.ListModules();
        var i = moduleInfoList.GetEnumerator();

        setPrefix('Installed KBs on your Instance');

        while (i.MoveNext())
        {
            Microsoft.Dynamics.AX.Metadata.MetaModel.IModuleInfo moduleInfo = i.get_Current();
            System.String moduleName = moduleInfo.get_Name();

            setPrefix(moduleName);

            var updatesHotfixesEnumerator = updateProvider.ListObjects(moduleName).GetEnumerator();;
            while (updatesHotfixesEnumerator.moveNext())
            {
                System.String axUpdateName = updatesHotfixesEnumerator.get_Current();
                Microsoft.Dynamics.AX.Metadata.MetaModel.AxUpdate axUpdateObject = updateProvider.Read(axUpdateName);

                utcdatetime installedDateTime = axUpdateObject.get_AppliedDateTime();
                setPrefix(strFmt('Name %1, Installed on %2', axUpdateObject.get_Name(), installedDateTime));
                var listKb = axUpdateObject.get_KBNumbers().GetEnumerator();
                while (listKb.MoveNext())
                {
                    info(listKb.get_Current());
                }
            }
        }
    }

    public  Microsoft.Dynamics.AX.Metadata.Providers.IMetadataProvider getDiskMetadataProvider(Microsoft.Dynamics.ApplicationPlatform.Environment.IApplicationEnvironment _Instance)
        {
            Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration diskProviderConfiguration = new Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration();

        diskProviderConfiguration.AddMetadataPath(_Instance.get_Aos().get_PackageDirectory());

            Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory metadataProvicerFactory = new Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory();

            return metadataProvicerFactory.CreateDiskProvider(diskProviderConfiguration);
        }

     

}

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++