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 :
Finance | Project Operations, Human Resources, ...
Answered

Understanding entity schema

(0) ShareShare
ReportReport
Posted on by 8

Hi,

We would like to create tables on our database in order to clean data before importing it to dynamics 365 finance. 

Is there an easy way to understand the column width and type of an entity so data is the correct size and type for an entity without going into the AOT and checking the entity column by column?

Thanks

Astrid

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

    What is the key problem? You said that you want to "understand", but isn't your goal to generate the tables?

    You could use the metadata API to read entity definitions and generate SQL code to create your tables.

  • AstridMalanka Profile Picture
    8 on at

    I am not sure what you mean. We want to import data into release products v2. And I needed to know that the column length of the item number and product number.

    what is the metadata api?

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

    Sorry, I'm just trying to understand your situation and your problem and I interpreted your first sentence as that you're trying to create tables matching entity schema. Are you saying that those tables aren't relevant to your problem?

    So again, what is the key problem? That you don't want to access Visual Studio? If so, AOT browser may be a solution for you. Or that you want to see properties of multiple fields at once? Or you want to generate code with field length validation? Or what?

    I'm assuming that your case is more complex than just checking the length of item and product numbers, because checking them would take much less time then this discussion.

    The metatada API is a set of classes for getting information about F&O objects, such as classes, tables or - in your case - data entities and their fields.

  • AstridMalanka Profile Picture
    8 on at

    Let me try to explain.

    I need to create a table that the schema matches the vendor v2 entity (for example).

    the entity, has 170+ columns. I can go to the entity on the AOT and check column by column the column type, but I was looking if there is an easier way to do it.

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

    Aha, so you want to create such a table, after all. What I meant in my first reply was that you could generate the table automatically. As I explained, the metadata API (for example) gives you information about entity fields, therefore you can iterate all 170 fields and generate SQL code for creating the table.

    Isn't this a better solution to "I need to create a table that the schema matches the vendor v2 entity" then mere "knowing the column legth" (which also ignores other cricial details, such as data types)?

  • AstridMalanka Profile Picture
    8 on at

    I am still not sure how can I use the metadata API.

    I have never used it.

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

    Here you can see a simple example of using it from a C# console application: Use D365FO metadata API in .Net.

    It can be used from inside F&O as well (example), but it doesn't seem necessary in your case.

    There are several other ways how to get information about entity fields, but I suspect that they don't contain enough details about data types.

  • AstridMalanka Profile Picture
    8 on at

    thanks, i will try it out

  • AstridMalanka Profile Picture
    8 on at

    Hi,

    We have been working on the code sample, but we are not familiar with the library, therefore we are not sure on how to adapt the code to get the entity metadata.

    Thanks

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

    It's a pity that you didn't tell us what problem you're dealing with, but anyway, I've created an example for your exact scenario. It's still just a demo; it doesn't cover all cases.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Dynamics.AX.Metadata.MetaModel;
    using Microsoft.Dynamics.AX.Metadata.Storage;
    using Microsoft.Dynamics.AX.Metadata.Storage.Runtime;
    
    namespace DataEntityFields
    {
        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);
    
                AxDataEntityView entity = metadataProvider.DataEntityViews.Read("VendVendorV2Entity");
    
                foreach (AxDataEntityViewMappedField entityField in entity.Fields.Where(f => f is AxDataEntityViewMappedField))
                {
                    var datasource = FindDataSource(entity.ViewMetadata.DataSources, entityField.DataSource);
                    if (datasource == null)
                    {
                        continue;
                    }
    
                    AxTable table = metadataProvider.Tables.Read(datasource.Table);
                    AxTableField field = table.Fields[entityField.DataField];
    
                    AxTableFieldString stringField = field as AxTableFieldString;
                    if (stringField != null)
                    {
                        AxEdtString edt = null;
                        if (stringField.ExtendedDataType != "")
                        {
                            edt = metadataProvider.Edts.Read(stringField.ExtendedDataType) as AxEdtString;
                        }
    
                        int stringSize = edt?.StringSize ?? stringField.StringSize;
                        Console.WriteLine($"{entityField.Name} (String {stringSize})");
                    }
                }
    
                Console.ReadLine();
            }
    
            private static AxQuerySimpleDataSource FindDataSource(IEnumerable dataSources, string dataSourceName)
            {
                foreach (AxQuerySimpleDataSource ds in dataSources)
                {
                    if (ds.Name == dataSourceName)
                    {
                        return ds;
                    }
    
                    return FindDataSource(ds.DataSources, dataSourceName);
                }
    
                return null;
            }
    
        }
    }

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans