web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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.

  • Verified answer
    GirishS Profile Picture
    27,845 Moderator on at

    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.

  • Eisenberk Profile Picture
    87 on at

    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,

  • GirishS Profile Picture
    27,845 Moderator on at

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

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    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,845 Moderator on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 274 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 219

#3
Subra Profile Picture

Subra 202 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans