Change Table & Field Properties in Ax 2012 by X++

Change Tables Field Properties:

static void ChangeTableFieldProperties(Args _args)
{
TreeNode FldsRoot = treeNode::findNode(@"\Data Dictionary\Tables\ChangeLabel\Fields");
TreeNodeIterator FldsIterator;
TreeNode Flds;
str newLabel = "Cust Name";
str property;

FldsIterator = FldsRoot.AOTiterator();
Flds = FldsIterator.next();
while(Flds)
{
if(Flds.AOTgetProperty('Name') == 'CustomerName')
{
property = setProperty(Flds.AOTgetProperties(),"Label",newLabel);
info(property);
Flds.AOTsetProperties(property);
Flds.AOTsave();
Flds.AOTrefresh();
}
Flds = FldsIterator.next();
}
}

Change Tables Properties:

static void ChangeTableProperties(Args _args)
{
xInfo xInfo = new xInfo();
treeNode node = xInfo.rootNode().AOTfindChild("Data Dictionary");
treeNode childNode;
treenodeIterator nodeIterator;
str properties;
str tables;
str newLable = "Change label";
;

node = node.AOTfindChild("Tables");
nodeIterator = node.AOTiterator();
childNode = nodeIterator.next();
while (childNode)
{
tables = childNode.treeNodeName();
if(tables == "ChangeLabel")
{
properties = setProperty(childNode.AOTgetProperties(), "Label", newLable);
info(properties);
childNode.AOTsetProperties(properties);
childNode.AOTsave();
childNode.AOTrefresh();
break;
}
childNode = nodeIterator.next();
}
}
Advertisements

2 thoughts on “Change Table & Field Properties in Ax 2012 by X++

  1. Hi, i have used your first code to change the table field properties.
    but when it gives info that job is done, then we have to have again from AOT. there are any other option when job run then automatically field save.

    Like

    • Hi Akshay,

      Yes we can do that like below..
      //Below line is to take the table name to node
      TreeNode tablenode = treeNode::findNode(@”\Data Dictionary\Tables\CustTable”);

      //You can use below two lines of code after the if loop
      tablenode.AOTsave();
      tablenode.AOTsave();

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s