Showing related records on a child form

Hi All,

I have a requirement, for that I have to show all the lines of “Lines” tab of “VendInvoiceJournal” form on a new form(lets say it “MaintainChargesFrm”), and have to implement some more functionality (leave that, for now I have to show only some field of all the lines of “Lines” tab of “VendInvoiceJournal” form in a grid of “MaintainChargesFrm” form ). I have added a button as “Maintain Charges” On “VendInvoiceJournal” form (as shown in the attached pic), and on the click of that button, the newly created form should open with all the records as of “Lines” tab of “VendInvoiceJournal” form.

For now, on the click of “Maintain Charges” button, the form “MaintainChargesFrm” opened but no record shown.

I have written the code on Clicked() method of the button as below:

void clicked()
{

int recordsCount;
VendInvoiceTrans _vendInvoiceTrans;
container con;
Args args;
str multiSelectString;

args = new Args();
recordsCount = VendInvoiceTrans_ds.recordsMarked().lastIndex(); // gets the total records selected
_vendInvoiceTrans = VendInvoiceTrans_ds.getFirst(1);

while (_vendInvoiceTrans)
{
// storing recid of selected field in container
con = conIns(con, 1, _vendInvoiceTrans.RecId);

// converting container to string with comma separated
multiSelectString = con2Str(con, ‘,’);

_vendInvoiceTrans = VendInvoiceTrans_ds.getNext(); // moves to next record
}
// passing string
args.parm(multiSelectString);
// calling menu item
new MenuFunction(menuitemDisplayStr(OWMaintainCharges_MI), MenuItemType::Display).run(args);
}

And the code for init() method of the newly created form (“MaintainChargesFrm” form) is as below:

public void init()
{

container con;
int i;
str multipleRecords;

super();
// getting string value from caller
multipleRecords = element.args().parm();

// string to container
con = str2con(multipleRecords,’,’);

// for sorting
for(i = 1; i<= conLen(con);i++)
{
VendInvoiceTrans_ds.query().dataSourceTable(Tablenum(VendInvoiceTrans)).addRange(fieldNum(VendInvoiceTrans, RecId)).value(SysQuery::value(conPeek(con,i)));
}
}

Please help me to sort out the problem.

Thank You!!!

You didn’t say what’s the problem, so let me focus on problems in your design.

Shouldn’t you simply filter lines by ID of the selected journal?

If so, first get rid of the serialization to a list of IDs and then filtering by this. It has many problems - it’s slow, the range value length is limited etc. I wouldn’t never use that.

Then remove all code from clicked() (you shouldn’t put any business logic to such methods); just use a menu item, set its DataSource property to VendInvoiceJour (to pass records to the other form) and implement all logic in the target form.

In init(), get the record sent by the source form (args.record()) and extract the journal ID.
Then add a range to your form’s datasource to filter by the journal ID.

Thanks Martin for the reply!!
As I am new to AX form development, I dont get much more what you said.
Will you please tell me what and where should I write the code to get the same records on new form

Before talking about code, do you understand the design?

  1. There won’t be any code in Form1
  2. In Form2, you’ll get the journal header from Form1
  3. You’ll filter your datasource in Form2 (VendInvoiceTrans) by adding a range for journal ID.

If this is clear, please tell me which part you can’t handle.

Your code above get data from Args and add form ranges, therefore if you understand what you wrote before, you shouldn’t have much troubles with implementing this solution.

Yes, I understood the design. I got difficulty in getting the Journal header from From1 and based on filtering the Datasource in Form2.

In my first reply, I told you to use args.record() in init() to get the record sent by Form (in the same way as your code calls parm()).

It’s also wise to check whether the type of record is what you expect. For example:

Args args = element.args();
VendInvoiceJour header;

// One way
header = args.record() as VendInvoiceJour;

// Alternative approach
if (args.dataSet() == tableNum(VendInvoiceJour))
{
    header = args.record();
}

Thank you Martin!! It helped me.