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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to filter records for lookup of reference group.

(0) ShareShare
ReportReport
Posted on by 6,478
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

I have the same question (0)
  • Verified answer
    Johnny Profile Picture
    6,478 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.

  • Community Member Profile Picture
    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!!!

  • Johnny Profile Picture
    6,478 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).

  • Verified answer
    Community Member Profile Picture
    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!!!

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
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans