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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Filtering the datasource of a dialog lookup

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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?

  • Douglas Noel Profile Picture
    3,905 on at

    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
    on at

    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().

  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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
    on at

    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.

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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.

  • Mariano Gracia Profile Picture
    on at

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

  • Jo Neetesonne Profile Picture
    175 on at

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

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans