Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

loop through all data entities in D365FO

Posted on by Microsoft Employee
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

  • DimanC Profile Picture
    DimanC 113 on at
    RE: loop through all data entities in D365FO

    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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: loop through all data entities in D365FO

    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
    DimanC 113 on at
    RE: loop through all data entities in D365FO

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: loop through all data entities in D365FO

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

          }

    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: loop through all data entities in D365FO

    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
    Community Member Microsoft Employee on at
    RE: loop through all data entities in D365FO

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: loop through all data entities in D365FO

    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?

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: loop through all data entities in D365FO

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

  • Stefan Lundquist Profile Picture
    Stefan Lundquist 55 on at
    RE: loop through all data entities in D365FO

    loop through table: DMFDefinitionGroupEntityXMLFields

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: loop through all data entities in D365FO

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans