Issue: How to lookup fields of an existing table (Standard/Customized) in D365?
Solution: Below code should be implemented to show lookup of existing table(s).
public void lookup()
{
Query lookupQuery;
QueryBuildDataSource qbds;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(SqlDictionary), this);
// Display the Name field in the lookup form.
sysTableLookup.addLookupfield(fieldnum(SqlDictionary, Name));
// Create a custom Query
lookupQuery = new Query();
qbds = lookupQuery.addDataSource(tablenum(SqlDictionary));
qbds.addRange(fieldNum(SqlDictionary, fieldId)).value((SysQuery::valueNot(0)));
qbds.addSortField(fieldNum(SqlDictionary, Name), SortOrder::Ascending);
qbds.addRange(fieldNum(SqlDictionary, shadow)).value(queryValue(0));
qbds.addRange(fieldNum(SqlDictionary, flags)).value(queryValue(0));
qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum("YourTableName")));
// Multiple tables can be added as range, if required
// qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum(InventTable)));
sysTableLookup.parmQuery(lookupQuery);
sysTableLookup.performFormLookup();
}
Solution: Below code should be implemented to show lookup of existing table(s).
public void lookup()
{
Query lookupQuery;
QueryBuildDataSource qbds;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(SqlDictionary), this);
// Display the Name field in the lookup form.
sysTableLookup.addLookupfield(fieldnum(SqlDictionary, Name));
// Create a custom Query
lookupQuery = new Query();
qbds = lookupQuery.addDataSource(tablenum(SqlDictionary));
qbds.addRange(fieldNum(SqlDictionary, fieldId)).value((SysQuery::valueNot(0)));
qbds.addSortField(fieldNum(SqlDictionary, Name), SortOrder::Ascending);
qbds.addRange(fieldNum(SqlDictionary, shadow)).value(queryValue(0));
qbds.addRange(fieldNum(SqlDictionary, flags)).value(queryValue(0));
qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum("YourTableName")));
// Multiple tables can be added as range, if required
// qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum(InventTable)));
sysTableLookup.parmQuery(lookupQuery);
sysTableLookup.performFormLookup();
}
No comments:
Post a Comment