Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Filtering the datasource of a dialog lookup

Posted on by Microsoft Employee

Hello,in a class I am creating a simple dialog with a dialogfield such as:

DialogField dialogPurchId = dialog.addField(extendedTypeStr(PurchId));

This shows my purchase order headers in a look up,no problem.However, is there a way to filter this look up? For example I only want to show open orders in this lookup?

Regards

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Filtering the datasource of a dialog lookup

    Jo, you still have references and reference filters on EDT level. They do almost identical job for unbound controls are relations did.

  • Jo Neetesonne Profile Picture
    Jo Neetesonne 175 on at
    RE: Filtering the datasource of a dialog lookup

    Oh, how I miss relations on EDT level... :-)

  • RE: Filtering the datasource of a dialog lookup

    Look at class Tutorial_RunbaseForm, it is what are you looking for

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Filtering the datasource of a dialog lookup

    Your purchidlookup() method is an instance method (which is correct) - how did you want to call it without creating an instance?

    Create an instance of the class where you've defined your lookup method and pass it into the parameter. Trivial.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering the datasource of a dialog lookup

    Hmm I don't have a separate class for generating the dialog, it all gets generated in main method.So I guess I'm gonna have to change it altogether.

    Cheers.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Filtering the datasource of a dialog lookup

    Your last parameter is wrong - it needs to be the class where you have implemented your lookup method. It surely isn't the standard dialog class.

    If you call registerOverrideMethod() from the object where you've implemented the lookup method, use this as the third parameter.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering the datasource of a dialog lookup

    Try to implement lookup without parameters in same class you create dialog. Form control you can get inside lookup method by calling dialog.formRun().controlCallingMethod().

  • Douglas Noel Profile Picture
    Douglas Noel 3,905 on at
    RE: Filtering the datasource of a dialog lookup

    Hi,

    I think the 'redirected' method should have the save number and type of parameters as the original one.

    FormStringControl.lookup() doesn't have any parameter.

    Maybe you're going to change your declaration and try to access the control using something like element.controlCallingMethod()

    only a hint, I do not really know.

    regards

    Douglas

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering the datasource of a dialog lookup

    Cheers;

    I have added the following method :

    private void purchidlookup(FormStringControl _control)

    {

       SysTableLookup          sysTableLookup;

       QueryBuildDataSource    queryBuildDataSource;

       QueryBuildRange         querybuildrange;

       Query                   query = new Query();

       queryBuildDataSource = query.addDataSource(tablenum(PurchTable));

       querybuildrange = queryBuildDataSource.addRange(fieldNum(PurchTable,PurchStatus));

       querybuildrange.value(enum2str(PurchStatus::Canceled));

       sysTableLookup = SysTableLookup::newParameters(tablenum(PurchTable), _control);

       sysTableLookup.addLookupfield(fieldnum(PurchTable, PurchId),  true);

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();

    }

    And to the class, I have added:

       control = dialogPurchId.control();

       control.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(m_UpdatePurchLinePrices, purchidlookup),dialog);

    Yet this gives me an error when i try to open the lookup:

    Error executing code: FormStringControl (object), method Lookup called with invalid parameters.

    Any ideas?

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Filtering the datasource of a dialog lookup

    Sure, it is possible. Implement a custom lookup method (with filters) and link it to your dialog field through DialogField.registerOverrideMethod().

    Search internet for examples if needed.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans