我有一个表单,用户可以在下拉列表/组合框中选择AOT中的任何可用表格(第1号表示salestable)
现在我想在no中选择的表中的所有字段的2中进行查找。我需要根据表名来得到这个... 我希望查找包含字段的系统名称和字段的标签。 这可能吗?我已经尝试了很多解决方案,但我还没有得到它。
任何建议都将不胜感激。
答案 0 :(得分:1)
有两种主要方法可以做到这一点我可以想到。反思并使用SysModelELements
表。第一种方式会给你这个名字&标签,第二个不会可靠地给你标签。
第一份工作用反思证明了这一点。第二个显示它与SysModelElements
表,并且更快,但不会给你标签。您可以使用DictField
对象枚举标签(如第二种方法所示)。
第一种方法是最可靠的,因为第二种方法可能有一些我没想过的情况,例如表格视图或地图。
方法1:
static void Job96(Args _args)
{
str tableName = 'SalesTable';
DictTable dictTable;
DictField dictField;
int i;
dictTable = new DictTable(tableName2id(tableName));
if (dictTable)
{
for (i=1; i<=dictTable.fieldCnt(); i++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(i));
info(strFmt("Field Name: '%1'; Field Label: '%2'; IsSystem: %3",
dictField.name(),
dictField.label(),
dictField.isSystem()));
}
}
else
{
error(strFmt("Table '%1' not found!", tableName));
}
}
方法2
static void Job97(Args _args)
{
tableName tableName = 'SalesTable';
SysModelElement tables;
SysModelElement fields;
DictField dictField;
while select tables
where tables.ElementType == UtilElementType::Table &&
tables.Name == tableName
join fields
where fields.ElementType == UtilElementType::TableField &&
fields.ParentModelElement == tables.RecId
{
dictField = new DictField(tables.AxId, fields.AxId);
info(strFmt("Field Name: '%1'; Field Label: '%2'; IsSystem: %3",
dictField.name(),
dictField.label(),
dictField.isSystem()));
}
}