is it possible to create an index on an AX table using X++
You can create a table dynamically and add fields (as below)
but I need to add a Index as well
thanks
David Hills
code from Hulya http://dynamicsuser.net/forums/p/32852/172633.aspx
#AOT
Name name;
str tname;
NumberOf recordCount;
TreeNode treeNode,trv;
AOTTableFieldList fieldnode;
str s;
;
super();
treeNode = TreeNode::findNode(#TablesPath);
treeNode.AOTadd("NewTable"+this.ID).applObjectId();
treeNode=treeNode.AOTfindChild('NewTable'+this.ID);
treeNode.AOTcompile(1);
treeNode.AOTsave();
treeNode.AOTfindChild('NewTable'+this.ID);
fieldnode=treeNode.AOTfirstChild();
fieldnode.addString('Namee');
fieldnode=fieldnode.AOTfindChild('Namee');
//tn=treeNode::findNode(@"\NewTable"+this.ID);
//tname=tn.treeNodeName();
}
//Find the Indexes node for the table we just created
childNode = infolog.findNode('\\Data
Dictionary\\Tables\\AA_NewTable_dh\\Indexes');
//Add the Index
childNode.AOTadd(indexName);
childNode.AOTsave();
//Find the Index in the Indexes node
childNode = infolog.findNode('\\Data
Dictionary\\Tables\\AA_NewTable_dh\\Indexes\\'+indexName);
//Add the a field to the Index
childNode.AOTadd(myTestField);
childNode.AOTsave();
childNode.AOTcompile();
"static void CreateTableplusField(Args _args)
{
#AOT
Name name;
str tname;
NumberOf recordCount;
TreeNode treeNode,trv;
TreeNode childNode;
AOTTableFieldList fieldnode;
str s;
str stableName, sTestField, sIndexName;
;
sTablename = 'AA_TestTable';
sTestField = 'TestField';
sIndexName = 'TestIndexIdx';
treeNode = TreeNode::findNode(#TablesPath);
treeNode.AOTadd(sTablename).applObjectId();
treeNode=treeNode.AOTfindChild(sTablename);
treeNode.AOTcompile(1);
treeNode.AOTsave();
treeNode.AOTfindChild(sTablename);
fieldnode=treeNode.AOTfirstChild();
fieldnode.addString(sTestField);
fieldnode=fieldnode.AOTfindChild(sTestField);
childNode = infolog.findNode('\\Data Dictionary\\Tables\\'+ sTablename
+'\\Indexes');
//Add the Index
childNode.AOTadd(sIndexName);
childNode.AOTsave();
//Find the Index in the Indexes node
childNode = infolog.findNode('\\Data Dictionary\\Tables\\'+ sTablename
+'\\Indexes\\'+sIndexName);
//Add the a field to the Index
childNode.AOTadd(sTestField);
childNode.AOTsave();
childNode.AOTcompile();
appl.dbSynchronize(tablename2id(sTablename), false);
}