Friday, December 23, 2011

UtilElements table

Being an AX developer, you must be familiar with .aod files. (For the uninitiated, .aod files contain all the application level code). Ever wondered, what is inside those .aod files, how the data is organised etc. Well, AX provides us a way to do just that. The answer lies in the UtilElements table.

This table forms part of the broader topic of Reflection APIs in AX. More on this later.

UtilElements table belongs to a set of Util prefix tables which contain all element definitions. In other words, these tables give you direct access to the content inside .aod files.

Lets see this table in action.

Suppose you want to find all classes beginning with Proj and that have been changed within the last month. One way to achieve this will be as follows.

static void findProjClasses(Args _args)
{
    UtilElements ue;
    ;
    
    while select name from ue
        where ue.RecordType == UtilElementType::Class
            && ue.Name like 'Proj*'
            && ue.ModifiedDateTime >
                DateTimeUtil::addDays(DateTimeUtil::getSystemDateTime(), -30)
    
    {
        info(strfmt("%1", ue.Name));
    }
}

You can also use the UtilElements table to find out objects belonging to a particular layer or maybe to fulfil a more specific requirement like listing all the static methods belonging to a particular table. For eg,

static void findStaticEmplTable(Args _args)
{
    UtilElements ue;
    
    while select name from ue
        where ue.recordType == UtilElementType::TableStaticMethod
            && ue.ParentId == tableNum(EmplTable)

    {
        info(strfmt("%1", ue.name));
    }
}

Wednesday, December 21, 2011

Repeatable read

This keyword can be used in cases where you merely want to read the record multiple times without any need to update. You use it like this.

select repeatableRead salesTable where salesTable.SalesStatus == SalesStatus::Invoiced;

On the database level, repeatableRead maintains a shared lock on all the records selected by the select statement, meaning that the records maintain the original values and no updates/deletes are allowed.