AX 2012: Setting Labels in X++

To set Label property of all the fields of a table in AOT, you may refer to the following code which loops through all the fields of a table and sets their Label property with their Name property.

static void MAKSetLabels(Args _args)
    SysDictTable    dictTable = new SysDictTable(tableNum(CustTable));
    SysDictField    dictField;
    TreeNode        treeNode;
    FieldId         fieldId = dictTable.fieldNext(0);
    str             fieldName;

    while (fieldId)
        dictField = dictTable.fieldObject(fieldId);

        if (dictField.isSql() && !dictField.isSystem())
            treeNode = dictField.treeNode();
            fieldName = treeNode.AOTgetProperty(#PropertyName);
            treeNode.AOTsetProperty(#PropertyLabel, fieldName);
            info(strFmt("Field name: %1 | Field label: %2",
                treeNode.AOTgetProperty(#PropertyName),         //Field name
                treeNode.AOTgetProperty(#PropertyLabel)));      //Field label
            treeNode = null;

        fieldId = dictTable.fieldNext(fieldId);

Leave a Reply

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

You are commenting using your 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