Notifications
Announcements
No record found.
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
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.
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?
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.
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.
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)?
I am still not sure how can I use the metadata API.
I have never used it.
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.
thanks, i will try it out
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.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 660 Most Valuable Professional
André Arnaud de Cal... 549 Super User 2025 Season 2
Sohaib Cheema 307 User Group Leader