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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to get the active record from a grid to another grid

(0) ShareShare
ReportReport
Posted on by 454

Hi ,

I am new to AX 2012 . I am having one Form and there i have 2 Grid controls. In First grid i have Item Group. In the second grid i have fields like ItemNo, and Product name. If i select one Item Group in first grid , the second grid should be populated with the ItemNo and Product Name  which is assigned with that Item Group.  Help me on this. 

Regards,

Ram.

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Ram,

    You should be able to accomplish this using the datasource joins. You can look at InventTransferOrders form as an example.

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    So basically you first grid has Item groups and second grid has Items. And when you select an Item group, you want to filter the second grid, showing only items of that Item group. I assume that your data source tables are ItemGroup and InventTable.

    In most cases, such filtering should happen automatically based on table relations and form data source properties. But in case of Item group, InventTable is not directly related to ItemGroup, instead the relation goes through InventItemGroupItem. One item can be in many item groups.

    So, you need to add some code, which should be triggered in the active method of your ItemGroup data source. There you need to add code that re-executes the InventTable data source query, filtering only the relevant records.

    Here's some example on how to define ranges in executeQuery method of a form data source: community.dynamics.com/.../699211

  • WillWU Profile Picture
    22,361 on at

    Hi Ram Kumar,

    If the Product Name field is display method, you could call it in datasource field(ItemNo) modified():

    public void modified()
    
    {
    
       table_ds.cacheCalculateMethod(tableMethodStr(tableName,MethodName));
    
       super();
    
    }

    If not, you just have to fill the Product Name field by its value in the modified() method.

  • Ram Kumar Profile Picture
    454 on at

    Hi Nikolaos,

    Could you please give me some code samples to get the active record value of one grid and accessing that in an another grid. I am new to AX.

    Regards,

    Ram

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    You can get the active record of a data source simply by referring to the data source name.

    For example if your data source name is ItemGroup, then you can type ItemGroup to access that table buffer.

    And you can type ItemGroup.ItemGroupId to get value of ItemGroupId.

    So, you need two parts:

    1) In active method of ItemGroup data source, call executeQuery of InventTable data source

    2) In executeQuery method if InventTable data source, use ItemGroup.ItemGroupId to filter the values.

  • Ram Kumar Profile Picture
    454 on at

    Hi Nikolaos,

    Here is my form. Here the Itemgroup grid's stringedit control datasource is InventItemGroup. On the right hand side the Itemgroup datasource is InventItemGroupitem datasource and Invemttable datasource for Itemid. If i select Audio in the left hand side the grid on the right hand side should be filtered based on the Audio itemgroup. I dont know how to and where to write the code since i am new to ax 2012. Help me on this. I need some code samples to do this

    0042.Screenshot_5F00_1.png

    Thanks & Regards,

    Ram

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    If you read my previous replies, you should know following details:

    1) Where to write code

    2) How to fetch the selected ItemGroupId

    3) How to filter a data source (in this case InventTable) in x++

    Could you try to describe what you learnt so far from the replies and suggestions, and what kind of code you tried to write?

  • Ram Kumar Profile Picture
    454 on at

    // Datasource- Inventitemgroupitem
    public void executeQuery()
    {
       QueryBuildRange qbr;
    
       
       this.query().dataSourceTable(tableNum(InventItemGroupitem)).addRange(fieldNum(InventItemGroupitem, ItemGroupId)).value(queryValue(InventItemGroup.ItemGroupId));
    
    
        super();
    }
    
    // Datasource- Inventitemgroup
    public void selectionChanged()
    {
    
        super();
        if (inventItemGroup.ItemGroupId)
        {
            inventItemGroupitem_ds.executeQuery();
        }
    
    
    
    }

    Hi Nikolaos,

    I have set the datasource property for my second as inventitemgroupitem. Here is my code for execute query in Inventitemgroupitem. I have marked breakpoint for selection change method in Inventitemgroup (First grid) it triggers whenever i selecting. and also i marked another breakpoint in execute query . the value for the range is  what itemgroup i was selected in the first grid , is applied to the query but my second grid is not filtered. If my code was wrong correct me on this.

    Regards,

    Ram

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Ahh, so your data sources are InventItemGroup and InventItemGroupItem! I thought that they are InventItemGroup and InventTable.

    In this case you don't need any x++ code to achieve the filtering.

    Just set JoinSource of InventItemGroupItem data source to point in InventItemGroup data source, and try to set Link type to Delayed. Does it work?

    Whenever you have two tables that are directly related to each other, you don't need any x++ development to handle the filtering.

  • Ram Kumar Profile Picture
    454 on at

    Hi Nikolaos,

    I  tried what you have said, It works .

    Thanks & Regards,

    Ram

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans