In the below example, I will be overriding lookup for form ‘InventJournalTransfer’, and the custom field ‘LSLoadId’. To override an existing lookup method of a form, we will perform the following steps:
Step 1: Go to the field of the form on which you want to apply lookup, then expand events, then right-click on OnLookup and click on ‘Copy event handler method’, paste it into a class, and follow the code as shown below.
Step 2: Code
/// <summary>
/// InventJournalTrans form event handler
/// </summary>
class LSInventJournalTransForm_EventHandler
{
/// <summary>
/// Look up of Loads
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
[FormControlEventHandler(formControlStr(InventJournalTransfer, InventJournalTable_LSLoadId), FormControlEventType::Lookup)]
Public static void InventJournalTable_LSLoadId_OnLookup (FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource qbds;
FormControlCancelableSuperEventArgs cancelableArgs = e as FormControlCancelableSuperEventArgs;
SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(WHSLoadTable), sender);
qbds = query.addDataSource(tableNum(WHSLoadTable));
sysTableLookup.parmQuery(query);
sysTableLookup.addLookupfield(fieldNum(WHSLoadTable, LoadID));
sysTableLookup.addLookupfield(fieldNum(WHSLoadTable, LoadDirection));
sysTableLookup.addLookupfield(fieldNum(WHSLoadTable, TrailerNumber));
sysTableLookup.setLabel("@WAX3273");
sysTableLookup.performFormLookup();
cancelableArgs.CancelSuperCall();
}
}
You can also check out my previous blog: Workflow in Microsoft Dynamics 365 FO
Need help? Connect Atul
Latest posts by Atul Yadav (see all)
- D365 Data entitiy Insert method COC - October 30, 2024
- D365 Joins - October 16, 2024
- D365 Find method and Exist method - October 9, 2024