用X++代码创建表
用代码创建表的代码,在这里记录一下:
static void CreateNewTable(Args _args)
{
#AOT
TreeNode treeNode = TreeNode::findNode(#TablesPath);
DictType dictType;
TreeNode treeNodeField;
str tableName = 'Student';
str fieldName1 = 'StudentNum';
str fieldName2 = 'StudentName';
AOTTableFieldList afl;
str property;
void addField(str fieldName,str label,str HelpText,str ExtendedDataTypeName)
{
afl.addString(fieldName);
property = strFmt(@"Properties
Label #%1
HelpText #%2
ExtendedDataType #%3
EndProperties
",label,HelpText,ExtendedDataTypeName);
treeNodeField = afl.AOTfindChild(fieldName);
treeNodeField.AOTsetProperties(property);
}
;
//Add Table;
treeNode = treeNode.AOTadd(tableName);
//Add Fields
afl = treeNode.AOTfirstChild();
addField(fieldName1,"Student Number","The Number of Student.","AccountNum");
addField(fieldName2,"Student Name","The Name of Student.","AccountName");
//Save
treeNode.AOTcompile(1);
treeNode.AOTsave();
//Restore Extended Data Type's Properties
treeNode.AOTrestore();
//Synchronize Table
appl.dbSynchronize(SysDictTable::newTreeNode(treeNode).id());
}
{
#AOT
TreeNode treeNode = TreeNode::findNode(#TablesPath);
DictType dictType;
TreeNode treeNodeField;
str tableName = 'Student';
str fieldName1 = 'StudentNum';
str fieldName2 = 'StudentName';
AOTTableFieldList afl;
str property;
void addField(str fieldName,str label,str HelpText,str ExtendedDataTypeName)
{
afl.addString(fieldName);
property = strFmt(@"Properties
Label #%1
HelpText #%2
ExtendedDataType #%3
EndProperties
",label,HelpText,ExtendedDataTypeName);
treeNodeField = afl.AOTfindChild(fieldName);
treeNodeField.AOTsetProperties(property);
}
;
//Add Table;
treeNode = treeNode.AOTadd(tableName);
//Add Fields
afl = treeNode.AOTfirstChild();
addField(fieldName1,"Student Number","The Number of Student.","AccountNum");
addField(fieldName2,"Student Name","The Name of Student.","AccountName");
//Save
treeNode.AOTcompile(1);
treeNode.AOTsave();
//Restore Extended Data Type's Properties
treeNode.AOTrestore();
//Synchronize Table
appl.dbSynchronize(SysDictTable::newTreeNode(treeNode).id());
}