您可以在StringEdit控件中使用EDT TableName,並且可以在查找中獲取所有表。
Output:
Ways2 :
X++ | d365FO - Create a list of table name lookup
Scenario / expected result
We have a string control on a form, then we'd like to have a lookup which shows all of table name from AOT.
Solution
The overview processes are:
- Create a temp table with metadata-populate method
- Add a lookup method to the table that will be a form's data source
- Add a lookup method on the form's control
Create 'populate' method
using Microsoft.Dynamics.AX.Metadata.MetaModel;
public class aaaTableNameListTemp extends common
{
public static aaaTableNameListTemp populate()
{
aaaTableNameListTemp table;
var tables = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::TableNames();
while (tables.MoveNext())
{
table.clear();
table.initValue();
table.TableName = tables.Current;
table.insert();
}
return table;
}
}
For example, if our table is 'aaaTable' table. Add 'lookupTableName' method on that table.
public void lookupTableName(FormStringControl _control)
{
SysTableLookup lookup;
QueryBuildDataSource qbds;
Query q = new Query();
qbds = q.addDataSource(tableNum(aaaTableNameListTemp));
qbds.addSortField(fieldNum(aaaTableNameListTemp, TableName), SortOrder::Ascending);
lookup = SysTableLookup::newParameters(tableNum(aaaTableNameListTemp),
_control,
true);
lookup.addLookupField(fieldnum(aaaTableNameListTemp, TableName), true);
lookup.parmQuery(q);
lookup.parmTmpBuffer(aaaTableNameListTemp::populate());
lookup.performFormLookup();
}
On your desired control, override 'lookup' method and put the below code.
[Control("String")]
class Grid_FormName
{
public void lookup()
{
aaaTable.lookupFormName(this);
}
}
............................................
[Control("String")]
class DGS_EditWorkTemplateSettings_WorkTemplateTable
{
/// <summary>
///
/// </summary>
public void lookup()
{
SysTableLookup lookup;
QueryBuildDataSource qbds;
Query q = new Query();
qbds = q.addDataSource(tableNum(DGS_TableNameListTmp));
qbds.addSortField(fieldNum(DGS_TableNameListTmp, TableName), SortOrder::Ascending);
lookup = SysTableLookup::newParameters(tableNum(DGS_TableNameListTmp),
this,
true);
lookup.addLookupField(fieldnum(DGS_TableNameListTmp, TableName), true);
lookup.parmQuery(q);
lookup.parmTmpBuffer(DGS_TableNameListTmp::populate());
lookup.performFormLookup();
}
}
[Control("String")]
class DGS_EditWorkTemplateSettings_WorkTemplateField
{
/// <summary>
///
/// </summary>
public void lookup()
{
SysTableFieldLookup tableFieldLookup; // function for lookup field
TmpSysTableField tmpSysTableField; // to catch selected lookup value
str tableName = DGS_EditWorkTemplateSettings_WorkTemplateTable.valueStr();
Query query = new Query();
;
query.addDataSource(Global::tableName2Id(tableName));
tableFieldLookup = new SysTableFieldLookup(query);
tmpSysTableField.DictTableId = (Global::tableName2Id(tableName));
tableFieldLookup.performLookupField(this, tmpSysTableField); // lookup display label description
}
}
// 在Query中尋找有多少Table:
public static DGS_TableNameListTmp populateByQuery(str QueryName)
{
DGS_TableNameListTmp table;
Query q;
QueryRun queryRun;
int i,j,dsCount,rangeCount;
QueryBuildDataSource ds;
queryRun = new QueryRun(QueryName);
q = queryRun.query();
dsCount = q.dataSourceCount();
for (i = 1; i <= dsCount; i++)
{
ds = q.dataSourceNo(i);
table.TableName = tableId2Name(ds.table());
table.insert();
}
return table;
}
留言列表