Skip to main content

Notifications

Announcements

No record found.

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

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    You are right, I was running the old version apparently. thanks!!!

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Understanding entity schema

    ProductSubType is an enum, which is saved as INT in database. But it's true that enums can be exported either by the value (INT) or the symbol (string), depending on context.

    Are you sure you're testing the updated code? I'm getting correct string sizes. If you're complaining about the same problem as before, maybe you're running old code.

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    Regarding the issue of exporting the entity staging table to a BYOD, we encounter an issue when trying to export Released Product V2, that the staging table has a column PRODUCTSUBTYPE which has a number and it is an INT column  as an export to the database, but when we import it, it is an string 20 on the entity, there was another column on that entity with the same kind of issue.

    Regarding your code, I do understand that the code needs work, we have adapted the code to include other type of columns, but we cannot understand what the string is always 10, we have debug the code and the data it gets, it is also 10. we do understand that the default for a string column while created is 10 too, we just don't understand how to get the real number, and not the default one.

    thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Understanding entity schema

    Your statement about BYOD sounds strange to me. If a wrong schema was created in the external database, the export would fail, wouldn't it? Which specific field are you talking about?

    Regarding the code, I've updated to include information from EDT. But note that I gave you the code as a demonstration of how to use metadata API, so you can start building your own solution. My intention isn't writing the whole thing for you.

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    Hi, We have tried but we are finding that all the string columns return a value of 10, which is not correct on any case, and we cannot find any attribute to add. Any idea where we are going wrong?

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    Thanks, I am sorry if I am not clear, but the issue is that I need to create a table on my database that matches the schema of the entity. We are trying to do some data quality work on the data we are going to import to dynamics and one of the issues we want to avoid is to have the wrong type of data or incorrect lengt. 

    Exporting the table to the BYOD does not work as the schema table can differ from the entity. One column on the entity was a string and on the staging table was an int.

    I will test the code you sent. thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Understanding entity schema

    Another approach may be publishing data entities to BYOD and taking the schema from there.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Understanding entity schema

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

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    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

  • AstridMalanka Profile Picture
    AstridMalanka 8 on at
    RE: Understanding entity schema

    thanks, i will try it out

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans