Custom lookup example code x++ AX 2012

Example of custom lookup for itemid on PurchLine , form : PurchTable

public void lookup()
{
 SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);
 Query query = new Query();
 QueryBuildDataSource queryBuildDataSource, queryBuildDataSource2;
 QueryBuildRange queryBuildRange, queryBuildRange2;
 QueryBuildLink queryBuildLink;
 BuyBackScheme BuyBackScheme;
 str FilterCategory;
 //super();

 queryBuildDataSource = query.addDataSource(tablenum(InventTable));
 //add by Fanddy
 if(InventBuyerGroup::find(PurchTable.ItemBuyerGroupId).InventOwnership == InventOwnership::MD)
 {
 queryBuildDataSource = queryBuildDataSource.addDataSource(tableNum(PdsApprovedVendorList));
 queryBuildDataSource.joinMode(JoinMode::InnerJoin);
 queryBuildDataSource.relations(true);

 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,PdsApprovedVendor)).value(PurchTable.OrderAccount);
 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,ValidFrom)).value(strFmt(“<= %1″,DateTimeUtil::date(DateTimeUtil::removeTimeZoneOffset(PurchTable.createdDateTime,TimeZone::GMTPLUS0700_BANGKOK_HANOI_JAKARTA))));
 queryBuildDataSource.addRange(fieldNum(PdsApprovedVendorList,ValidTo)).value(strFmt(“>= %1″,DateTimeUtil::date(DateTimeUtil::removeTimeZoneOffset(PurchTable.createdDateTime,TimeZone::GMTPLUS0700_BANGKOK_HANOI_JAKARTA))));

 }
 //END by fandd

 sysTableLookup.addLookupfield(fieldnum(InventTable, itemId));
 sysTableLookup.addLookupMethod(‘itemName’);
 sysTableLookup.addLookupMethod(‘itemGroupId’);
 sysTableLookup.addLookupfield(fieldnum(InventTable, NameAlias));
 sysTableLookup.addLookupMethod(tableMethodStr(InventTable,pdsDefaultOrderType));
 sysTableLookup.addLookupfield(fieldnum(InventTable, RetailType));
 sysTableLookup.parmQuery(query);
 sysTableLookup.performFormLookup();

}

happy daxing !

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s