Get active datasource from one form to another

Hello,

I have two forms.
One form has two grids:

Grid 1: Where I select a certain record and that changes the records in grid two.

Grid 2: Detailed records about grid 1 records.

In form 2 I have the grid 2 set up the same way but I need the active record from grid 1 so that the records are the right ones. The problem is I don’t know how I can get active records from form 1, grid 1 into form 2 grid , so that I have the same result as in form 1.

It’s not clear how you open Form2. If you use a menu item button and set its DataSource property correctly, the active record will be automatically passed to Form2. There you can get it by calling element.args().record().
Also note that a dynamic link is normally applied automatically by the system, therefore no code is needed.

1 Like

Yes, I open Form2 by using an Display Menu Item Button on Form1. But it doesn’t work it always give me the first record(Grid1), records(Grid2).

Example:
Grid 1:

  • Letter
  • Number
  • Sign

Grid 2 (Letters):

  • a
  • b
  • c

And it’s always the first one in form 2 while in form one it changes depenting on what i click in grid 1

Are you saying that it won’t use the selected record at all, or that it works just when pressing the button but not when switching records in Form1? The latter requires a dynalink. If you’re trying to achieve it by code, please show it to us.
Also, which version of AX are you using? Please always attach a version tag (e.g. AX 2012 or D365FO) when creating a new thread.

Sorry, I’m new
I’m using ax 2012

Form 1 is working properly and when I select a record in grid 1 it changes the records in grid 2, the problem is in form 2, when I open it with the menu item button it always shows me the records as if I had selected the first record of form 1, grid 1. And as of now I don’t have any code.

But do I understand correctly that you want to get data in Form2 reloaded if you switch records in Grid1 of Form1? If so, you’ll need a dynalink (either created automatically or from code).
Before anything else, make sure that DataSource property of the menu item button is set to the data source used by Grid1. It probably won’t make any difference, but it’s better to rule out the possible problem here.