D365/AX7: Using SysReferenceTableLookup For Reference Group In Form (Missing LookUpReference Event)

Requirement

Vendor Address Lookup in purchase order creation form (PurchCreateOrder).

Sample Code

For simple form control, we can use SysTableLookUp class & write code in onlookup event of form control.The sample code is mentioned in below line:

D365/AX7: Extend Form Control OnLookup Event On Standard Form

But for reference group control in form, SysTableLookup doesnot work.There is  one different class called  SysReferenceTableLookup For Reference Group In Form.Also in D365 there is no event related LookUpReference method.So i am using OnLookup event.

class AcxPurchCreateOrderFormEvents
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(PurchCreateOrder, PurchTable_AcxDeliveryPostalAddressVend), FormControlEventType::Lookup)]
public static void PurchTable_AcxDeliveryPostalAddressVend_OnLookup(FormControl sender, FormControlEventArgs e)
{
VendTable vendTable;
Common common;
PurchTable purchTable = sender.formRun().dataSource(formDataSourceStr(PurchCreateOrder,PurchTable )).cursor();
VendTable = VendTable::find(purchTable.OrderAccount);

SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup ::newParameters(tableNum(LogisticsPostalAddress),sender);
Query q = new Query();
QueryBuildDataSource qbds;
qbds = q.addDataSource(tableNum(LogisticsPostalAddress));
sysTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Location));
sysTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Address));
sysTableLookup.parmQuery(q);
sysTableLookup.performFormLookup();
FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
ce.CancelSuperCall();
}

}


Leave a Reply