This sample code is used to show Customer Name in lookup, In AX 2009 we had name field in CustTable but now its moved to DirPartyTable. We still have name() in CustTable which we can use to display name in lookups.
AX 2009
client static void lookupInterCompanyItemId(FormStringControl lookupCtrl, DataAreaId _dataAreaId = "")
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), lookupCtrl);
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tablenum(InventTable));
;
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId));
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemName));
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemGroupId));
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemType));
if(_dataAreaId)
qbds.company(_dataAreaId);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
AX 2012
client static void lookupInterCompanyItemId(FormStringControl lookupCtrl, DataAreaId _dataAreaId = "")
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), lookupCtrl);
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tablenum(InventTable));
;
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId));
sysTableLookup.addLookupfield(fieldnum(InventTable, NameAlias));
sysTableLookup.addLookupMethod(tableMethodStr(InventTable,itemGroupId));
sysTableLookup.addLookupfield(fieldnum(InventTable, ItemType));
if(_dataAreaId)
qbds.company(_dataAreaId);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}