Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : kVMetzBwTqSpSc4r3pOEks
Finance | Project Operations, Human Resources, ...
Answered

EventHandler on lookup method defined in table

Like (0) ShareShare
ReportReport
Posted on 8 Jun 2023 14:11:22 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
    27,823 Moderator on 08 Jun 2023 at 14:39:21
    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
    12,554 Moderator on 08 Jun 2023 at 14:35:35
    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
    27,823 Moderator on 08 Jun 2023 at 14:34:00
    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
    87 on 08 Jun 2023 at 14:32:55
    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
    27,823 Moderator on 08 Jun 2023 at 14:26:03
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete