Override an existing lookup method event handler

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.

On Lookup
On Lookup

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

Atul Yadav
Latest posts by Atul Yadav (see all)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *