Working With Kernel Based Classes and AOT Based Tables in Dynamics AX

by | Oct 16, 2017 | Development, Dynamics AX

Thinking in the Abstract

If you have seen some of my blog articles before, you may have noticed that I look at automating documentation from time to time. This article will expand on the concept a bit, and use different components of Dynamics AX to accomplish or demonstrate some of the more abstract ways to retrieve information.

In the past, I have used TreeNode (https://msdn.microsoft.com/en-us/library/gg958198.aspx) to work with AOT-based objects. However, if working with just tables and fields, a lot of information can be retrieved by using some kernel based classes. I will demonstrate a couple here.

The first kernel based class is the DictTable class (https://msdn.microsoft.com/en-us/library/dicttable.aspx). DictTable allows you to retrieve information specific to a table. To use the object, the X++ code will resemble the following:

 

At this point, the dictTable object is instantiated and will be referencing the data for the CustTable table. Information about the table can be retrieved via method calls from the object. The DictTable documentation in the link above provides an example of retrieving and displaying some of the information on the table.

The next kernel based class is the dictField class (https://msdn.microsoft.com/en-us/library/dictfield.aspx). DictField is used to retrieve field information from a table. More on this in a moment, as I want to bring in another kernel based object before we start working with DictField.

The next kernel based object I want to bring in is the SQLDictionary table (https://msdn.microsoft.com/en-us/library/sqldictionary.aspx). This table describes the current state of the database with respect to the table and field metadata. For the purposes of our discussion, we need to work with two fields, tabId and fieldId. The tabId column is used to denote fields that exist in a specific table. FieldId is the field number of the field within the specific table. IF the fieldId value is 0, it is the ‘header’ record for the table, and it does not represent an actual field in the table.

NOTE: Do NOT go in and start randomly changing information in the SQLDictionary table. This will cause many issues within the system.

So, why do I bring this up? Well, using SQLDictionary in combination with DictField, you can work in the abstract with table information.

Here is an example:

 

The above code, when placed in a job, will list out all the fields in the table, the name, the base type (string, int, real, etc.), IF the field has a label defined on it, the label Id will be displayed, and the actual label text for this field. By looking at the documentation page for DictField, you can see what information you can retrieve from the method calls.

Also, using these objects, you can work abstractly, and actually work with data in the tables. Here is an example:

 

Notice the code in the if statement. IF we get a SQLDictionary record for CustTable where there is a field named ACCOUNTNUM, we can use that information to fill in data. The above code gets the field Id from the SQLDictionary record, then it uses the common object and DictTable to create a table buffer based on CustTable. Then it sets the AccountNum field to BillTest, and finally inserts the record into the table.

Also, please note that additional information can be retrieved by using the SysDictField object instead of DictField (https://msdn.microsoft.com/en-us/library/sysdictfield.aspx). This inherits from DictField, and expands on the functionality provided.

In summary, as I have stated before, knowing some of the kernel based classes provides some rather unique tools for many different purposes. I hope I have provided some basis for thinking outside of the box on using Dynamics AX based objects.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

may

28may1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Designing the Software Collaboratively

june

02jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Conference Room Pilots

03jun10:00 am10:30 amWhy Levridge Grain? Streamlining Sales Contracts

04jun11:00 am12:00 pmConfab With Stoneridge - Livestream - Customer Insights

04jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Dealing with Challenges Mid-Project

09jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Customizations vs Configurations and How You Manage Them

10jun10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Buyer

11jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Data Migration - Early and Often

15jun(jun 15)9:00 am16(jun 16)4:00 pmDynamics 365 Finance and Supply Chain Management Training for AX 2012 Developers

16jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Environment Management and Deployments

17jun10:00 am10:30 amWhy Levridge Grain? Best Practices for Managing Load Orders for Grain Processors

17jun12:00 pm1:00 pmMobilizing an efficient, streamlined AP department with AP Automation

17jun2:00 pm3:00 pmGuide for B2B Businesses: Tackling Supply Chain Optimization and Customer Experience Challenges

18jun11:00 am12:00 pmConfab with Stoneridge - Livestream - Enterprise Asset Management and Preventative Maintenance

18jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Testing - Definition and Activities

23jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Training for All

24jun10:00 am11:00 amOn the Job with Dynamics 365 - Manufacturing Production Manager

25jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Going Live

30jun1:00 pm1:30 pmHow to Implement Microsoft Dynamics: Hypercare

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X