Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Reuse the lookup

Posted on by Microsoft Employee

Hello,

I have a reference group control on a form which is having a lookupreference method on corresponding field in form datasource. 

Now i have a another form where i have the same reference group control and i want the same lookupreference method to be used there.

What should i do to avoid writing the same code in the lookupreference method of this new form? 

The same reference group control may be used in another forms gets created in future. everytime i don't want to write the same code in lookupreference method on each of those new forms.

Can a Class provide the solution for reuse of the code?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Reuse the lookup

    Thanks Martin.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,056 Most Valuable Professional on at
    RE: Reuse the lookup

    The solution is simple - extract your code to a separate method (typically placed on the table you're looking up). Your replacementLookup() method will have just a single line - a call to the table method.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Reuse the lookup

    Hi Rachit,

    I want to use standard framework lookup with a filter on it. Due to this filter, i have to override the lookupreference method and apply that filter in it.

    so i  want to avoid override this lookupreference method & writing filter code again & again on every new form where i use that reference group control.

  • Suggested answer
    Rachit Profile Picture
    Rachit 4,015 User Group Leader on at
    RE: Reuse the lookup

    Hi VDY,

    Adding to Dominic's advise you can find similar example at \Forms\HcmGoal\Data Sources\HcmGoal\Fields\ClosedByManager\Methods\lookupReference().

    Regarding your question :"Everytime I don't want to write the same code in lookupreference method on each of those new forms.", if you do not want to use the standard framework lookup which comes on the basis of relations defined on the table then you will need to override the lookupReference method, otherwise you need to rethink about the relations between your table.

     

    Hope that helps.

     

     

  • Suggested answer
    dolee Profile Picture
    dolee 11,279 on at
    RE: Reuse the lookup

    For lookup method they are usually created at the Table.

    Then override the form > datasource > field's lookup method call that lookup method instead.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans