ENTERPRISE

Microsoft Dynamic AX 2009 : Reflection APIs (part 1) - Table Data API

11/16/2013 2:30:20 AM
The X++ system library includes three APIs that can be used to reflect on elements. They are described in the following sections.

1. Table Data API

Suppose that you want to find all classes whose names begin with Invent and that have been modified within the last month. The following example shows one way to conduct your search.

static void findInventoryClasses(Args _args)
{
UtilElements utilElements;

while select name from utilElements
where utilElements.RecordType == UtilElementType::Class
&& utilElements.Name like 'Invent*'
&& utilElements.ModifiedDateTime >
DateTimeUtil::addDays(DateTimeUtil::getSystemDateTime(), -30)
{
info(strfmt("%1", utilElements.Name));
}
}


The UtilElements table provides access to all elements. The RecordType field holds the concept. Other fields in the UtilElements table that can be reflected on are Name, CreatedBy, CreatedDateTime, ModifiedBy, and ModifiedDateTime.

Because of the nature of the table data API, the UtilElements table can also be used as a data source in a form or a report. A form showing the table data is available from Tools\ Development Tools\Application Objects\Application Objects. In the form, you can use the standard query capabilities to filter and search the data.

Some elements have sub-elements associated with them. For example, a table has fields and methods. This parent/child association is captured in the ParentId field of the sub-element. The following job finds all static method elements on the CustTable table element by selecting only table static method elements whose ParentIdCustTable table ID. equals the

static void findStaticMethodsOnCustTable(Args _args)
{
UtilElements utilElements;

while select name from utilElements
where utilElements.recordType == UtilElementType::TableStaticMethod
&& utilElements.ParentId == tableNum(CustTable)
{
info(strfmt("%1", utilElements.name));
}
}


Notice the use of field lists in the select statements in the examples in this section. Each record in the table also has a binary large object (BLOB) field that contains all the metadata, source code, and bytecode. This BLOB field can’t be interpreted from X++ code, so you don’t need to fetch it. When you specify a file list to the select statement with fields from the primary index, fetching the actual record is avoided, and the select statement returns the result much faster. The primary index contains these fields: RecordType, ParentId, Name, and UtilLevel.

The UtilLevel field contains the layer of the element. The following job finds all parent elements in the USR layer.

static void findParentElementsInUSRLayer(Args _args)
{
UtilElements utilElements;

while select recordType, name from utilElements
where utilElements.ParentId == 0
&& utilElements.utilLevel == UtilEntryLevel::usr
{
info(strfmt("%1 %2", utilElements.recordType, utilElements.name));
}
}


Elements can have IDs. The UtilElements table can’t provide ID information. To get ID information, you must use the UtilIdElements table. The two tables are both views on the elements in the .aod files; the only difference is the inclusion of the ID field in the UtilIdElements table. The following code is a revision of the previous job that also reports IDs.

static void findParentElementsInUSRLayer(Args _args)
{
UtilIdElements utilIdElements;

while select RecordType, Id, Name from utilIdElements
where utilIdElements.ParentId == 0
&& utilIdElements.UtilLevel == UtilEntryLevel::usr
{
info(strfmt("%1 %2 %3",
utilIdElements.RecordType,
utilIdElements.Name,
utilIdElements.Id));
}
}


Although we have discussed two tables that contain the .aod files in this section, all the application data files have a table reflection API similar to the ones we have mentioned. Table 1 lists some additional reflection tables.

Table 1. Reflection Tables
Table NameDescription
UtilElements, UtilIdElementsTables containing the .aod files, which contain elements.
UtilElementsOld UtilIdElementsOldTables containing the .aod files in the Old application folder. This information is useful during code upgrades.
UtilApplHelpTable containing the .ahd files, which contain online Help information for users.
UtilApplCodeDocTable containing the .add files, which contain developer documentation information for elements.
UtilCodeDocTable containing the .khd files, which contain developer documentation information for Dynamics AX system APIs.

All the tables listed in Table 1 have an associated class. These classes contain a set of static methods that are generally helpful. All the classes have the same name as the table, prefixed with an x.

Suppose you want to report the AOT path for MyForm from the table utilIdElements. You could use the xUtilIdElements function to return this information, as in the following code.

static void findAOTPathForMyForm(Args _args)
{
UtilIdElements utilIdElements = xUtilIdElements::find(
UtilElementType::Form, FormStr(MyForm));

if (utilIdElements)
info(xUtilIdElements::getNodePath(utilIdElements));
}


Note

When you use the table data API in an environment with version control enabled, the values of some of the fields are reset during the build process. For file-based version control systems, the build process imports .xpo files into empty layers in Dynamics AX. The values of the CreatedBy, CreatedDateTime, ModifiedBy, and ModifiedDateTime fields are set during this import process and therefore don’t survive from build to build.

Other  
  •  Microsoft Dynamic AX 2009 : Reflection System Functions
  •  Microsoft Enterprise Library : Banishing Validation Complication - Diving in With Some Simple Examples (part 4)
  •  Microsoft Enterprise Library : Banishing Validation Complication - Diving in With Some Simple Examples (part 3)
  •  Microsoft Enterprise Library : Banishing Validation Complication - Diving in With Some Simple Examples (part 2)
  •  Microsoft Enterprise Library : Banishing Validation Complication - Diving in With Some Simple Examples (part 1)
  •  Microsoft Enterprise Library : Banishing Validation Complication - How Do I Use The Validation Block?
  •  Microsoft Enterprise Library : Banishing Validation Complication - What Does the Validation Block Do? (part 2)
  •  Microsoft Enterprise Library : Banishing Validation Complication - What Does the Validation Block Do? (part 1)
  •  Microsoft Enterprise Library : A Cache Advance for Your Applications - How Do I Use the Caching Block (part 4) - Refreshing the Cache, Loading the Cache
  •  Microsoft Enterprise Library : A Cache Advance for Your Applications - How Do I Use the Caching Block (part 3) - Removing Items from and Flushing the Cache
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS