Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

x++ code to create table index

819 views
Skip to first unread message

David Hills

unread,
Jul 8, 2010, 6:04:24 AM7/8/10
to
Good Morning

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();

}


David Hills

unread,
Jul 8, 2010, 8:06:37 AM7/8/10
to
TreeNode childNode;
str tableName, myTestField, indexName;
;
indexName = 'myindexidx';
mytestField = 'FieldPK';

//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();

David Hills

unread,
Jul 8, 2010, 10:08:16 AM7/8/10
to

"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);
}

0 new messages