Create table in AX through X++

static void newTableCreate(Args _args)
{
TreeNode      treeNode;
#AOT
;
treeNode = TreeNode::findNode(#TablesPath);
treeNode.AOTadd("Table_Test");
SqlDataDictionary::synchronize();
}

The above code simply create table under AOT in dynamics AX.
In order to create fields under table, the below code helps:
static void Tbl(Args _args)
{
    #aot
    #properties
    SysDictTable sysdictTable;
    treenode trv;
    AOTTableFieldList fieldnode;
    str prop;
    int pos;
    ;
    trv = treenode::findNode(#TablesPath);
    //trv.AOTDrop('AAA',1);
    trv.AOTadd('AAA');

    trv = trv.AOTfindChild('AAA');
    trv.AOTcompile(1);
    trv.AOTsave();

    trv.AOTfindChild('AAA');

    fieldnode = trv.AOTfirstChild();
    fieldnode.addString('AccountNum');
    fieldnode = fieldnode.AOTfindChild('AccountNum');
    prop = fieldnode.AOTgetProperties();

    pos = findPropertyPos(prop,#PropertyExtendeddatatype); //find right place to put extended data type
    pos = strFind(prop,'ARRAY',pos,strLen(prop));
    pos = strFind(prop,'#',pos,strLen(prop));

    prop =strins(prop,extendedTypeId2name(ExtendedtypeNum(CustAccount)),pos + 1);
    // insert field of extended data type 'CustAccount'
    fieldnode.AOTsetProperties(prop);

    trv.AOTcompile(1);
    trv.AOTsave();

    trv.AOTRestore(); //to load assigned extended data type properties

    sysdictTable = sysdictTable::newTreeNode(trv);
    appl.dbSynchronize(sysdictTable.id());

}


Comments

Popular posts from this blog

Write/ Read to Excel Sheet

Table Methods in Ax 2012

Financial Dimensions in AX 2012