The easiest way to do lookup on your form control in D365 can be achieved by following the steps mentioned below.
- Go to your field where lookup needs to be created
- Expand the Events node of form control
- Right click OnLookup event and select "Copy event handler method"
- Create a new class and name it appropriately (Naming convention "FormName"+"EventHandler")
- In newly created class press Ctrl + V
public static void LC_AssetGroup_LC_AssetId_OnLookup(FormControl sender, FormControlEventArgs e)
{
}
Do your lookup code inside the handler, as shown below
FormControlEventHandler(formControlStr(SalesTable, LC_AssetGroup_LC_AssetId), FormControlEventType::Lookup)]
public static void LC_AssetGroup_LC_AssetId_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(AssetBook), sender);
queryBuildDataSource = query.addDataSource(tableNum(AssetBook));
queryBuildDataSource.addRange(fieldNum(AssetBook, Status)).value(strFmt('((Status == %1) || (Status == %2))', any2int(AssetStatus::Open), any2int(AssetStatus::Closed)));
sysTableLookup.addLookupField(fieldNum(AssetBook, AssetId), true);
sysTableLookup.addLookupMethod(tableMethodStr(AssetBook, assetName));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();