Hey!

Through D365FO metadata API you can access object properties and other informations from within .Net code.

This can be useful in automation scenarios, for security check or if you want to build something really cool like a development tool for D365FO.

Anyway, if you ever need something like that, here is an example:

using Microsoft.Dynamics.AX.Metadata.MetaModel;
using Microsoft.Dynamics.AX.Metadata.Storage;
using Microsoft.Dynamics.AX.Metadata.Storage.Runtime;
using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;

public class Demo
{
    public static void Main(string[] args)
    {
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory.GetApplicationEnvironment();
        var runtimeConfiguration = new RuntimeProviderConfiguration(environment.Aos.PackageDirectory);
        var metadataProvider = new MetadataProviderFactory().CreateRuntimeProviderWithExtensions(runtimeConfiguration);

        AxMenuItemDisplay menuItem = metadataProvider.MenuItemDisplays.Read("SalesTable");
        if (menuItem.ObjectType == MenuItemObjectType.Form)
        {
            AxForm form = metadataProvider.Forms.Read(menuItem.Object);
            foreach (AxFormPartReference part in form.Parts)
            {
                Console.WriteLine(part.Name);
            }
        }
    }
}

The above example will list all form parts from a specific form, based on a display menu item.

You’ll need references to:

  • Microsoft.Dynamics.ApplicationPlatform.Environment.dll
  • Microsoft.Dynamics.AX.Metadata.dll
  • Microsoft.Dynamics.AX.Metadata.Core.dll
  • Microsoft.Dynamics.AX.Metadata.Storage.dll

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

18 − 4 =