web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

loop through all data entities in D365FO

(0) ShareShare
ReportReport
Posted on by
I need a list of all Data Entity, along with its fields and field properties. So far I am using Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityView("AccountantEntity") to get the metadata of the named data entity. However I need to loop through all the data entity names, and I cant find a way to do that. Can someone help me out?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    MetadataSupport will help you with this part too:

    var entityNames = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityViewNames();
    var enumerator = entityNames.GetEnumerator();
    
    while (enumerator.MoveNext())
    {
        info(enumerator.Current);
    }
  • Stefan Lundquist Profile Picture
    55 on at

    loop through table: DMFDefinitionGroupEntityXMLFields

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Unfortunately my D365FO environment doesn't have any data in this table.

  • Community Member Profile Picture
    on at

    I also need to loop through each of the Data Entity fields as well
    How do I use the API similarly to reference the Data Entity fields?

  • Community Member Profile Picture
    on at

    My environment doesn't have any data in that table either

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Aha, so you know how to call GetDataEntityView() but you don't know what to do with the object.

    Unfortunately I can't look at the code right now. I assume the class has a property called Fields or something and you can iterate it in the same way as I showed above with the list of entity names.

  • Community Member Profile Picture
    on at

    I have found the answer, and this is my code. Thank you for helping me out.

    static public void loopDataEntity()

    {

          var entityNames = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityViewNames();

          var enumerator = entityNames.getEnumerator();

          void loopFields()

          {

              AxDataEntityView                axDataEntity;

              axDataEntity = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityView(enumerator.Current);

              var dataEntityFields = axDataEntity.Fields;

              var defEnum = dataEntityFields.GetEnumerator();

              while (defEnum.moveNext())

              {

                  defEnum.moveNext();

                  info(strFmt("field - %1", defEnum.Current.ToString()));

              }

          } //end of method loopFields

          ;

          while (enumerator.MoveNext())

          {

              enumerator.MoveNext();

              info(strFmt("Data entity -- %1", enumerator.current));

              loopFields();

          }

    }

  • DimanC Profile Picture
    113 on at

    Bit old topic, but I'll try luck.

    Looping through entities works fine.

    But I don't see a method in MetadataSupport that would retrieve entity extensions.

    There are corresponding methods for tables and classes ( Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTableExtensionsForTable and ::GetFormExtensionNames ), but nothing for entities.

    My aim is to list all entities we've extended.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    MetadataSupport has some methods for this purpose, but they're internal, therefore you can't call them.

    Nevertheless MetadataSupport class is just a façade simplifying the usage of the metadata API and you can use the API directly. For example:

    using Microsoft.Dynamics.ApplicationPlatform.Environment;
    using Microsoft.Dynamics.AX.Metadata.Storage;
    using Microsoft.Dynamics.AX.Metadata.Storage.Runtime;
    
    class Demo
    {        
        public static void main(Args _args)
        {    
            str packageDir = EnvironmentFactory::GetApplicationEnvironment().Aos.PackageDirectory;
    
            var runtimeProviderConfiguration = new RuntimeProviderConfiguration(packageDir);
            var provider = new MetadataProviderFactory().CreateRuntimeProvider(runtimeProviderConfiguration);
            var list = provider.DataEntityViewExtensions.ListObjectsForModel('MyModel');
        }
    }

    I've also noticed that one of the internal methods is used by DictDataEntity class, e.g. by getExtensionFieldNames(). It may be sufficient in some cases.

  • DimanC Profile Picture
    113 on at

    Thank you Martin!

    As soon as I learned how to navigate those metadata classes from C#, life seems easier.

    In my case answer was behind

    .GetPrimaryKeysWithModelInfo(); - it gives combination of entity extension name and its model.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans