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 data for a dialog lookup...

(0) ShareShare
ReportReport
Posted on by

Hello;

In a dialog, I add a lookup with an extendedtype as:

Dialog = new dialog("Select user");
dfile = dialog.addField(extendedTypeStr(HcmWorkerRecId),"User");

if(dialog.run() ) etc....

The problem is this lookup shows all the data in the look,all users in the example above.But I would like to filter that data.How can I achieve that?

*This post is locked for comments

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

    Override the lookupReference() method and reimplement the lookup. For example:

    // This is the new lookup
    private Common lookupWorker(FormReferenceControl _ctrl)
    {
        SysReferenceTableLookup  tableLookup = SysReferenceTableLookup::newParameters(tableNum(HcmWorker), _ctrl);
        Query query = new Query();
        QueryBuildDataSource qbds = query.addDataSource(tableNum(HcmWorker));
        
        // Here you would have some ranges    
    
        tableLookup.parmQuery(query);
        tableLookup.addLookupfield(fieldNum(HcmWorker, Person));
    
        return tableLookup.performFormLookup();
    }
    
    // This is how you override the standard lookup
    Dialog dialog = new Dialog("Select user");
    DialogField df = dialog.addField(extendedTypeStr(HcmWorkerRecId),"User");
    df.registerOverrideMethod(methodstr(FormReferenceControl, lookupReference), methodstr(YourClass, lookupWorker),
    this);
    dialog.run();
  • Community Member Profile Picture
    on at

    I see, cheers...

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

    If the reply answered your question, please mark it as the verified answer.

  • Community Member Profile Picture
    on at

    One more question,what happens if I use this in a form?

           dfile.registerOverrideMethod(methodstr(FormReferenceControl, lookupReference),methodstr(myform, lookupWorker), this);

    this gives me an error,since I have no seperate class for that method, and I have added the method under the form method.

    Regards

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

    You have to provide an object and method name. I assume it would work with a form as well (obviously you couldn't use methodStr(), because that's intended for class methods), nevertheless using a class makes better sense. Note that the method doesn't have to be on the object calling registerOverrideMethod() - you can set other object's reference as the third parameter.

  • Community Member Profile Picture
    on at

    Hello,this usage gives me :

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

    Error,any ideas why?

    Calling the lookup method with the following code:


    dfile.registerOverrideMethod(methodstr(FormReferenceControl,lookupReference),methodstr(erm_lookupoverrides, lookupWorker),this);

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

    Are you sure you're showing your actual code? The message seems to talk about the lookup() method, not about lookupReference() as in the code snippet.

  • Community Member Profile Picture
    on at

    Oh sorry,the correct error message is :

    Error executing code: FormReferenceGroupControl (object), method lookupReference called with invalid parameters.

    I did some test with using a standart strlookup instead of reference.(that didnt work either :()

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

    I tested my code and it worked. Does your method accept the same parameter as in my example and is dfile a reference group?

  • Community Member Profile Picture
    on at

    well here's the exact code :

    Dialog = new dialog("Select user");

    dfile  = dialog.addField(extendedTypeStr(HcmWorkerRecId),"User");

    dfile.registerOverrideMethod(methodstr(FormReferenceControl, lookupReference),methodstr(erm_lookupoverrides, lookupWorker),this);

    if(dialog.run())

    { etc...

    I have no idea why that isn't working :(

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