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)

lookup in item number

(0) ShareShare
ReportReport
Posted on by 327

hi all after creating sales order i am trying to add items.if i click item number it will open one lookup in that lookup ill get itemnum,name,drawing group,item group.i want to add one more field in that lookup is search name that field coming form eroresproduct table.whare can i add code for this...please see sample image 

itemlookup.png

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    AOT > \Forms\SalesTable\Data sources\SalesLine\Fields\ItemId\Methods\lookup()

    That method is overridden, and it drives that what form is being presented when you do a lookup depending on a bunch of settings and configurations.

    Debug which one it is for you, then you could customize the lookup form used based on your requirements afterwards.

    Most likely it is \Data dictionary\Tables\InventTable\Methods\lookupItem(), and all you need to do is enhance the query built there to join your additional datasource and add the lookup field.

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

    If you go to AOT > Forms > SalesTable > Data Sources > SalesLine > Fields > ItemId and open the lookup() method, you'll find that are several different ways that can be used (depending on context), but the most common one calls InventTable::lookupItem(). This method is used from several other places, therefore consider if you want to change them too.

  • Suggested answer
    Hamza Bin Mushtaq Profile Picture
    160 on at

    Hi Kathrik,

    As Vilmos and Martin explained above. 

    You can add the lookup field here in this method.

    community.JPG

    Please note, what Martin said that this method is called from other places also so you need to take care of that too.

    Regards,

    Hamza

  • karthik143 Profile Picture
    327 on at

    hi vilmos thanks for your replay i have written some code its not working please look into this

    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable),_ctrl);

       Query                   query = new Query();

       QueryBuildDataSource    qbds2;

       QueryBuildDataSource    qbds3;

       QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tableNum(InventTable));

       qbds2   = queryBuildDataSource.addDataSource(tableNum(EcoResProduct));

       qbds2.relations(true);

       sysTableLookup.addLookupfield(fieldNum(InventTable,ItemId));

       sysTableLookup.addLookupMethod(tableMethodStr(InventTable,itemGroupId));

       sysTableLookup.addLookupfield(fieldNum(InventTable,NameAlias));

       sysTableLookup.addLookupfield(fieldNum(InventTable,ItemType));

       sysTableLookup.addSelectionField(fieldNum(InventTable,Product));

       sysTableLookup.addLookupfield(fieldNum(EcoResProduct, SearchName));

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();

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

    Please never forget to explain your problem; "its not working" isn't sufficient.

    Fortunately I see your bug in this case.

    Let me explain what your code does. You've written this:

    sysTableLookup.addLookupField(fieldNum(EcoResProduct, SearchName));

    AX finds the ID of SearchName field in EcoResProduct table; lets say it's 5. The value is passed to addLookupField, so it looks like this:

    sysTableLookup.addLookupField(5);

    Notice that there is no information about table; sysTableLookup will use the table you specified SysTableLookup::newParameters(), which is InventTable. Therefore you're adding a field from InventTable (the one with ID 5), not from EcoResProduct as you intended. You need a different approach.

    One possibility is downloading SysMultiTableLoookup, which works similarly to SysTableLookup, but it allows you to choose the datasource.

    Alternatively you could create a view with those two tables joined and use the view in SysTableLookup.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Martin is right with the fieldId belonging to the original lookup table in your case.

    Take a look at an example similar to your request, where they have built a query to their needs and built a custom lookup form, that is what you could/should do as well:

    community.dynamics.com/.../how-to-create-form-lookup-lookup-multiple-tables

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