AOTTableFieldList AOTTableFieldList ,TableFieldNode;
TableName tableName = "SML_InventTableExt";
FieldName newFieldName = "SML_StorageLifeType";
Types newFieldType = Types::Integer;
int newFieldLength = 30;
str labelId = literalstr("@SML7726"); str ExtendedDataType ="";
ExtendedTypeId ExtendedTypeId = ExtendedTypeName2Id(ExtendedDataType); str EnumType = "SML_DaysUnitType"; TreeNode tableNode ,fieldNode ;
DictType DictType; #AOT
#Properties
#ACT_DynamicReport
;
tableNode = TreeNode::findNode(#TablesPath+'\\'+tableName) ;
AOTTableFieldList = TreeNode::findNode(#TablesPath+'\\'+tableName+'\\'+#ACT_AOTFieldsNode); fieldNode = AOTTableFieldList.AOTfindChild( newFieldname); if( fieldNode != null)
throw error(newFieldName + " allready exists in table " + tableName); if( ExtendedDataType )
{
if( ! ExtendedTypeId)
throw error( "ExtendedType type num error"); DictType = new DictType(ExtendedTypeId);
newFieldType = dictType.baseType();
}
else if (EnumType)
{
newFieldType = types::Enum;
} switch( newFieldType)
{
case Types::Date: AOTTableFieldList.addDate( newFieldName); break; case Types::Enum:
AOTTableFieldList.addEnum(newFieldName); break; case Types::Guid:
AOTTableFieldList.addGuid(newFieldName);
break; case Types::Int64:
AOTTableFieldList.addInt64(newFieldName);
break; case Types::Integer:
AOTTableFieldList.addInteger(newFieldName);
break; case Types::Real:
AOTTableFieldList.addReal(newFieldName);
break; case Types::String:
case Types::RString:
case Types::VarString:
AOTTableFieldList.addString(newFieldName);
break; case Types::DateTime:
AOTTableFieldList.addTime(newFieldName); break;
case Types::Container: // can add
continue; } TableFieldNode = AOTTableFieldList.AOTfindChild( newFieldName); if( newFieldType == types::String || newFieldType == Types::RString || newFieldType == Types::VarString )
TableFieldNode.AOTsetProperty("StringSize", newFieldLength); if( labelId)
TableFieldNode.AOTsetProperty("Label", labelId);
if( ExtendedDataType)
TableFieldNode.AOTsetProperty("ExtendedDataType", ExtendedDataType);
if( EnumType)
TableFieldNode.AOTsetProperty("EnumType", EnumType); tableNode.AOTcompile(1);
tableNode.AOTsave(); info("successed add field " + newfieldname);
在AX4.0中用JOB测试通过。
在AX部署代码时,若是涉及比较大的表的字段的新增,在表上用按钮直接操作,往往耗费很多的时间在等待AOT的编译上面,若是同一表要加多个字段的时候,等的简直让人抓狂,用这个job, 一次加一个字段,速度相当快。
原因在于在表上面用按钮直接加字段,系统会编译所有用到此TABLE的所有的相关VIEW和QUERY。
而用代码加字段,我们只编译了该TABLE所在的节点,所以比较快。