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)

Custom Lookup by joining InventSum and InventDim

(0) ShareShare
ReportReport
Posted on by 223

Dear Friends,

I am trying to create custom lookup in ax 2009 by joining InventSum and InventDim Tables to show up InventBatchId in Cross Company. The code that I used is given below. It is not showing the lookup at all. When I executed the same query in job I am getting the expected results. Please suggest me where I have made mistake. Your help is much appreciated.

The same query works fine for a single table, but while joining tables something goes wrong.

public void lookup()
{
    
Query query = new Query();
QueryBuildDataSource qbds1,qbds2;
SysTableLookup sysTableLookup;
QueryBuildRange qbr1,qbr2,qbr3;
//super();
;

query.allowCrossCompany(true);
query.addCompanyRange(StringEditCompany.valueStr());

qbds1   = query.addDataSource(tableNum(InventSum));
qbr1    = qbds1.addRange(fieldNum(InventSum,Itemid));
qbr1.value("1234");

qbds2   = qbds1.addDataSource(tableNum(InventDim));
qbds2.relations(true);
qbds2.fields().dynamic(NoYes::Yes);
qbr2    = qbds2.addRange(fieldNum(InventDim,InventLocationId));
qbr2.value("WH1");
qbr3   = qbds2.addRange(fieldNum(InventDim,WMSLocationId));
qbr3.value("PICK");

sysTableLookup = SysTableLookup::newParameters(tablenum(InventDim), this);
sysTableLookup.parmQuery(query);
sysTableLookup.addLookupfield(fieldnum(InventDim, InventBatchid), true);
sysTableLookup.parmUseLookupValue(true);
sysTableLookup.performFormLookup();
}

*This post is locked for comments

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

    The first check - did you verify in debugger that the method is called at all?

  • martinarul Profile Picture
    223 on at

    Hi Martin,

     I checked, the method gets called in the debugger.

    Regards

    Martin. A

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

    Can you describe the exact behavior, please? Are you saying that no drop-down gets open at all, or that it's empty?

    I suspect the problem is in the fact that InventDim isn't the root datasource of your query.

  • martinarul Profile Picture
    223 on at

    Hi Martin,

      You are exactly correct. The drop-down is empty. I also suspect that the InventDim is not the root datasource and that could be the reason.

    Can you suggest me how to keep InventDim as root datasource and build the query.

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Simply change the order of datasources in your query. Like this:

    Query query = new Query();
    QueryBuildDataSource dimDs, sumDs;
    
    dimDs = query.addDataSource(tableNum(InventDim));
    dimDs.addRange(fieldNum(InventDim, InventLocationId)).value("WH1");
    dimDs.addRange(fieldNum(InventDim,WMSLocationId)).value("PICK");
    
    sumDs   = dimDs.addDataSource(tableNum(InventSum));
    sumDs.relations(true);
    sumDs.joinMode(JoinMode::ExistJoin);
    sumDs.addRange(fieldNum(InventSum, ItemId)).value("1234");
  • martinarul Profile Picture
    223 on at

    Thanks a lot Martin. Now it works fine.

  • martinarul Profile Picture
    223 on at

    Hi Martin,

    I have another doubt, from the query you suggested. I want to add two more lookup fields ( one is field and the other is display method) from the joined table (InventSum)?

    Regards

    Martin. A

  • Suggested answer
    Shah Keyur Profile Picture
    365 on at

    You should create a custome view joining those tables. You can add your display method as field in view and use that view for your lookup method.

    This will also improve your performance of lookup query.

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

    A view is one option, SysMultiTableLookup is another.

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