AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.10.2017, 20:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
stoneridgesoftware: Working With Kernel Based Classes and AOT Based Tables in Dynamics AX
Источник: https://stoneridgesoftware.com/worki...n-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:

DictTable dictTable; TableId tableId = tableNum(CustTable); dictTable = new dictTable(tableId);

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/lib...ictionary.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:

// define a specific table Id, use the CustTable table in the demonstration TableId tableId = tableNum(CustTable); FieldId fieldId; SqlDictionary sqlDictionary; DictTable dictTable; DictField dictField; while select sqlDictionary where sqlDictionary.tabId == tableId && sqlDictionary.fieldId != 0 { dictField = new DictField(tableId,sqlDictionary.fieldId); info(strFmt("Name: %1, Label: %4, Label Id: %3, Base Type: %2", dictField.name(),dictField.baseType(),dictField.labelDefined(),dictField.label())); }

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:

static void AbstractionDemoJob(Args _args) { #define.AccountNum("ACCOUNTNUM") // define a specific table Id, use the CustTable table in the demonstration TableId tableId = tableNum(CustTable); FieldId fieldId; Common buffer; SqlDictionary sqlDictionary; DictTable dictTable; DictField dictField; dictTable = new dictTable(tableId); select firstOnly sqlDictionary where sqlDictionary.tabId == tableId && sqlDictionary.fieldId != 0 && sqlDictionary.name == #AccountNum; if (sqlDictionary) { fieldId = sqlDictionary.fieldId; buffer = dictTable.makeRecord(); buffer.(fieldId) = "BillTest"; buffer.insert(); } }

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/lib...dictfield.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.



Источник: https://stoneridgesoftware.com/worki...n-dynamics-ax/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
stephenmann: Technical History of Dynamics AX - From Axapta 3.0 to AX2012 Blog bot DAX Blogs 5 03.03.2017 10:22
stoneridgesoftware: How to use a View to Simplify Working with Query Classes in Dynamics AX Blog bot DAX Blogs 0 26.05.2016 18:11
emeadaxsupport: FAQ: Microsoft Dynamics AX Kernel Hotfixes Blog bot DAX Blogs 0 12.12.2014 00:11
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:04.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.