Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to filter records for lookup of reference group.

(0) ShareShare
ReportReport
Posted on by 6,420
public static void routOprNameLookup(FormControl    _control,
                                        InventRefId     _inventRefId)
    {
        Query                   query;
        //QueryBuildDataSource    qbdsNonConf;
        QueryBuildDataSource    qbdsProdRoute;
        QueryBuildDataSource    qbdsRouteOpr;
        QueryBuildRange         qbr;
        SysTableLookup          tableLookup;

        tableLookup     = SysTableLookup::newParameters(tableNum(RouteOprTable), _control);
        query           = new Query();

        qbdsRouteOpr = query.addDataSource(tableNum(RouteOprTable));
        qbdsProdRoute = qbdsRouteOpr.addDataSource(tableNum(ProdRoute));
        qbdsProdRoute.joinMode(JoinMode::InnerJoin);
        qbdsProdRoute.addLink(fieldNum(RouteOprTable, OprId), fieldNum(ProdRoute, OprId));

        qbr = qbdsProdRoute.addRange(fieldNum(ProdRoute, ProdId));
        qbr.value(_inventRefId);

        tableLookup.addLookupfield(fieldNum(RouteOprTable, OprId));
        tableLookup.addLookupfield(fieldNum(RouteOprTable, Name));


        tableLookup.parmQuery(query);

        tableLookup.performFormLookup();
    }

Hello,

I'm working on extension of "InventNonConformanceTableCreate" form.

The datasources there are "InventNonConformanceTable" and "inventDim" (I do not do any modification on InventDim table).

What I did is:

  1. I have added RefRecId field in "InventNonConformanceTable" table and made a relation to RecId of "RouteOprTable" table.
  2. I drag this RefRecId field to the InventNonConformanceTableCreate form, which created the reference group.
  3. I set the "Replacement field group" to "Auto report" which shows both fields of RouteOprTable table, but the problem here is that it displays all the records of RouteOprTable.

What I want to achieve:

  1. To have one additional field displayed within this reference group lookup from "ProdRoute" table, field "OprNum".
  2. As said on point 3 above, I want to filter the records based on the relation of InventNonConformanceTable and ProdRoute. The lookup should show the "OprNum, "OprId" and "Name" of the Operation that is selected on InventNonConformanceTable.

I tried different approaches with onLookup event, but was not able to achieve the desired solution.

I tried to code this, I call this method from onLookup event, but with it reference group lookup is not even opened:

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to filter records for lookup of reference group.

    Johnny,

    The display name which you are using is it a customized method or standard method? I think it is static method. So, this is the reason for the error. Can you please share the code of the display method? In case, if you are using the Name method from RouteOprTable table, it is a static method. Instead, you can use operationName() in ProdRoute table which also returns the same result as Name() in RouteOprTable  table. Post your result on this!!!

  • Johnny Profile Picture
    Johnny 6,420 on at
    RE: How to filter records for lookup of reference group.

    Thanks Jaya,

    I tried both of these approaches.

    When I use display method which returns the OprNum I'm getting error message that lookup can't use the void methods (My display method returns the correct value if I test it with job).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to filter records for lookup of reference group.

    You cannot add a field from other in the lookup other than the one which is specified using SysTableLookup. But the work around would be adding a display method for Name in the table that is specified in SysTableLookup and use it using addLookupMethod( ).

    If you want to display more fields from multiple tables, you can also create a view with a query joining all the datasources you want & then use that View in SysTableLookup.

    Hope this helps!!!

  • Verified answer
    Johnny Profile Picture
    Johnny 6,420 on at
    RE: How to filter records for lookup of reference group.

    I solved the filtering and the lookup display issue by changing SysTableLookup to SysReferenceTableLookup.

    But I still can't make to add the third field from another table.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans