Show fields on second form on the basis of SalesId selected from First form

Hi everyone,

I have created a form with data source CustInvoiceJour table. It is showing some fields from the datasource on the grid like SalesOrder, InvoiceAccount, InvoiceAmount, CreatedDate and DueDate. On top of the form, I have a dropdown for SalesId. Under it, I have a button.

Then, I have another form with datasource CustInvoiceTrans. There is a grid on this form as well. The grid has different fields like ItemId, Name, Qty, Price, Unit, SalesId, InvoiceId.

The problem is, we have to select a SalesId from drop-down from first form and press button. The second form will show the records on its grid on the basis of the Id selected in the first form.

I have read about Args class but all of the existing solutions are using the same datasources on both forms. My forms are using the different datasources. I select SalesId from dropdown and when I press button, The second form opens but without any data.

Any help…Thanks ALL!

What data do you want to see in the other form? Lines of the single selected invoice?

That the data sources are different is the typical case. For example, when you open invoices of a customer, you’ll get invoices filtered by the selected customer. The tables for customers and invoices are clearly different.

Normally you don’t have to do anything special for it, because AX automatically applies such a filter based on a table relation. Just make sure you use a menu item button to open the other form. And set its Data Source property accordingly - it’s often not necessary, but it’s a good idea anyway.

By the way, don’t forget that a single invoice may include several sales orders.

thanks for reply,

I have tried but failed.

On clicked method of First Form, I have written this code

void clicked()
Args args;
FormRun formRun;
args = new args(formstr(WAQAS_SecondDataForm)); // sending Args(record) to FormB
formrun = classfactory.formrunclass(args);
new MenuFunction(menuitemDisplayStr(WAQAS_SecondDataFormMenu), MenuItemType::Display).run(args);


AutoDeclaration Property of Button set to YES

on Second Form, On its Init method, I have written this code

public void init()
SalesLine _salesLine;
_salesLine = element.args().record();

I have made a Menuitem for second Form also.

When I open First Form and select a value, I get nothing Just debugger starts with this error message that i don’t understand

I just changed the datasource on second table making it same as first table and now, it is working fine. But this is not what I want. Please someone help

There are two problems with your code in clicked():

  1. It’s wrong.
  2. It’s not needed at all.

It’s wrong because you’re trying to open the form twice. And it’s not needed, because AX will do it for you. To create a menu item button, simply drag WAQAS_SecondDataFormMenu menu item to the form - no code in clicked() in needed!

Your code in init() has similar problems. It’s wrong because you assumes that you receive SalesLine in ement.args().record() (you sent SalesTable instead), and it’s not needed either.

As I said, the link is created automatically when there is a relation between tables. Unfortunately I don’t know which tables you’re actually using - you said you’re using CustInvoiceJour and CustInvoiceTrans, but your code is about different tables.

By the way, please always use Insert > Insert Code to paste source code. It preserves indentation, making code much easier to read.

thanks for reply,

ok, as It is my first ever post here, I don’t know how to use this forum, Thanks for guiding me.

Those CustInvoiceJour and CustInvoiceTrans are used in another forms (the actual project I was working on)

this is a new testing project, I made using SalesTable and SalesLines tables in the forms.

Do you mean to say, I do not require to any code at all. No code in both forms ?


I followed your instruction about creating a menuitem and it worked. About the real book, I did it with some weird coding as a workaround but I wanted to learn it the right way and I think this is the right way that you have showed.


I am verifying your answer too.

Great! :slight_smile:

There is one more benefit when using a dynamic link (dynalink) rather then setting a query range in init(), as you did. If open the child from though the menu item button and then switch to another record in the main form, AX will refresh the child form to show data for the newly selected record.