Home > X++ stuffs > TreeNode AOT Save – Did you know?

TreeNode AOT Save – Did you know?

Today I had a small requirement from one of my colleague stating he would like to update a particular table field property using X++ code for upgrade purpose.

So I wrote a sample job when I actually found that, if treeNode is traversed all the way to fields and then property is modified and saved. The table still shows that it should to be saved (You can see a red horizontal line prefixed to the table name)

Note: Although if you restore the table you can see the updated value. This gives an immersion to the user that that table needs to save manually else modified field properties value will be lost.

Reason: To set a field property you need to traverse all the way to field node so the treeNode object actually holds the following buffer

Path: \Data Dictionary\Tables\AddressCityTable_BR\Fields\CountryId:gls

Due to which when treeNode.AOTSave () is performed the treeNode object try to perform the save on the field and not on the table. This was bit strange thing to observe in the first place.

So to save the record I had to copy the treeNode instance to other object at the time of finding the table such that once the property is modified, the AOTSave/AOTCompile is made on the copied treeNode object.

Path: \Data Dictionary\Tables\AddressCityTable_BR Layer: gls

By this way I was able to save the record successfully at run-time, without any manual intervention.

Here is the sample code for the following exercise.

static void setTableProperties()
    TreeNode          treeNode;
    TreeNode          treeNode_TableName;
    AOTTableFieldList aotFields;

    // Find the table using TreeNode.
    treeNode = infolog.findNode(#TablesPath).AOTfindChild(#tableName);

    // Copying the tables path because using this 
    // INSTANCE we will save the AOT.
    treeNode_TableName = treeNode;

    // Go to the fields Node.
    aotFields = treeNode.AOTfindChild('Fields');

    // Mention the field Name
    treeNode = aotFields.AOTfindChild('CountryId');


    treeNode_TableName = null;
    treeNode = null;


This entry is shared since in most of the articles I found that they directly perform AOTSave on the instantiated treeNode.

Categories: X++ stuffs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: