TechNinjutsu‎ > ‎

AX7: MetaModel in D3FO to get a list of tiles for every workspace

posted Apr 25, 2018, 2:33 PM by d graham   [ updated Apr 25, 2018, 2:35 PM ]

Here is an example for how to work with the Dynamics 365 For Finance Operations Enterprise Edition(AX7) meta model in order to obtain some information about AOT objects. 

Forgive the naming and loops on loops on loops... this is just example code.

The example code is provided as-is and without warranty etc etc

using Microsoft.Dynamics.AX.Metadata.MetaModel;
using Microsoft.Dynamics.AX.Metadata.Service;
using Microsoft.Dynamics.AX.Metadata.Providers;
//using Microsoft.Dynamics.AX.Metadata.Kernel;

class TestClass
{
    //https://community.dynamics.com/365/financeandoperations/f/765/t/243050
    //https://community.dynamics.com/ax/b/goshoom/archive/2016/11/04/new-metadata-api

    public static void Main(args _args)
    {
        //https://community.dynamics.com/ax/b/ievgensaxblog/archive/2017/11/17/d365foe-get-list-of-installed-metadata-hotfixes-using-metadata-api
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();
        
        IMetadataProvider p = TestClass::getRunTimeMetadataProvider(environment);
        IMetaModelService service = new MetaModelServiceFactory().Create(p);
      
        var forms = service.GetFormNames();

        var e = forms.GetEnumerator();
        while (e.moveNext())
        {
            str formName = e.get_Current();
            AxForm form = service.GetForm(formName);
            if(form.Design.Style == Microsoft.Dynamics.AX.Metadata.Core.MetaModel.FormStyle::Workspace)
            {
                var controls = form.Design.GetAllControls();
                var eC = controls.GetEnumerator();
                while (eC.moveNext())
                {
                    AxFormControl curr = eC.get_Current();
                    if(curr is AxFormMenuFunctionButtonControl)
                    {
                        AxFormMenuFunctionButtonControl tile = curr;
                        if(tile.FormControlExtension == null)
                        {
                            continue;
                        }
                        var exp = tile.FormControlExtension.ExtensionProperties;
                        var eExp = exp.GetEnumerator();
                        while(eExp.moveNext())
                        {
                            Microsoft.Dynamics.AX.Metadata.MetaModel.AxFormControlExtensionProperty currProp = eExp.get_Current();
                            if(currProp.Name == 'tile')
                            {
                                info(strFmt("workspace: %1 control: %2 tile: %3",
                                formName,
                                curr.Name,
                                currProp.Value));
                            }
                        }
                    }
                }
            }
        }
    }

    //https://community.dynamics.com/ax/b/ievgensaxblog/archive/2017/11/17/d365foe-get-list-of-installed-metadata-hotfixes-using-metadata-api
    public static Microsoft.Dynamics.AX.Metadata.Providers.IMetadataProvider
            getRunTimeMetadataProvider(Microsoft.Dynamics.ApplicationPlatform.Environment.IApplicationEnvironment _environment)
    {
        Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration runtimeProviderConfiguration
                = new Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration(_environment.get_Aos().get_PackageDirectory());

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

        return metadataProviderFactory.CreateRuntimeProvider(runtimeProviderConfiguration);
    }

}
Comments