Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

EventHandler on lookup method defined in table

(0) ShareShare
ReportReport
Posted on by 87

Hello,

I am quite new (still) on D365.

I know that is possible to override forms lookup methods using event handlers. But, what happens when different forms call the same lookup defined in one table?

[PreHandlerFor(tableStr(SalesQuotationTable), tableMethodStr(SalesQuotationTable, lookupOpportunityId))]
public static void lookupOpportunityId(XppPrePostArgs args)
{
    //Some code
}

In this case, i don't see how to get the formcontrol. Usually, overriding a lookup method in form looks like:

 [FormControlEventHandler(formControlStr(formName, formControl), FormControlEventType::Lookup)]
public static void methodName(FormControl sender, FormControlEventArgs e)
{
    //Some code
}

Where i have the sender and a FormControlEventArgs, so i have the control, also i can cancel the double perform lookup.

It is possible to override the lookup in my first scenario? i did not find th way.

Thanks in advance,

Eisenberk.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: EventHandler on lookup method defined in table

    Creating common lookup method in table and calling everywhere in the lookup event handler is possible. But you cant override the lookup method at table level.

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: EventHandler on lookup method defined in table

    Hi, I don't think your overriding table lookup in your first scenario is possible. Your second scenario is possible and many blogs available for it.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: EventHandler on lookup method defined in table

    Yes, you need to override the lookup event handler wherever you need.

    Thanks,

    Girish S.

  • Eisenberk Profile Picture
    Eisenberk 87 on at
    RE: EventHandler on lookup method defined in table

    Hi Girish,

    In your example, I guess i have to override the look event handler in each form that i call the table lookup method, right?

    Thanks,

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: EventHandler on lookup method defined in table

    Hi Eisenberk,

    You create a table method with argument as FormControl, ControlValue. Later you can call that method on the lookup event handler.

    Create a common lookup method.

    public static common Lookup(FormReferenceControl _formReferenceControl,
                                    HcmWorkerRecId _workerRecid)
                                            
    {
        //add code for lookup method with query build datasource and query build range.
        return tableLookup.performFormLookup;
    }

    Now call this method on the lookup event handler.

    [FormControlEventHandler(formControlStr(formName, formControl), FormControlEventType::Lookup)]
    public static void methodName(FormControl sender, FormControlEventArgs e)
    {
        Call the lookup method from the table.
        TableName::lookup(sender,HcmWorkerRecid);
        FormControlCancelableSuperEventArgs  cancelSuperEventArgs = e as FormControlCancelableSuperEventArgs;
        cancelSuperEventArgs.CancelSuperCall();
    }

    Thanks,

    Girish S.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans