How to pass more than one record between two forms?
Asked Answered
Z

2

5

I want to pass more than one record between two forms. The user opens Form-A, selects multiple records and then clicks a button that opens Form-B. In Form-B there are two (or more) StringEdit controls and they should display values from the selected records.

I know how to pass only one record, to do that I use the following code in a method of Form-B:

if (element.args().parmEnumType() == enumNum(NoYes) 
 && element.args().parmEnum() == NoYes::Yes)
{
    myTable = element.args().record();
    stringEdit.text(myTable.Field);
}

How should I change my code so that I can set the text of another StringEdit control to the field value of the next record that the user selected?

Zenobiazeolite answered 10/4, 2015 at 7:40 Comment(0)
C
6

To do this, you can use an args to pass the records, which you will need to prepare in your Form-A, as below (taking the SalesTable as example);

int         recordsCount;
SalesTable  salesTable;
container   con;
Args        args = newArgs();

// gets the total records selected
recordsCount = salesTable_ds.recordsMarked().lastIndex();
salesTable = salesTable_ds.getFirst(1);
while(salesTable)
{
    // storing recid of selected record in container
    con = conIns(con,1, salesTable.RecId);
    salesTable = SampleTable_ds.getNext(); // moves to next record
}   
// passing container converted to string 
args.parm(con2Str(con,','));

Then on your Form-B, you will need to override the init() method to read the args you created,

In order to retrieve passed arguments in the recipient from. Override the init() method of new form as shown

public void init()
{
    container   con;
    int         i;
    super();       
    // string to container
    con = str2con(element.args().parm(),'','');    
    // for sorting
    for(i = 1;i<= conLen(con) ;i++)
    {
        salesTable_ds.query().dataSourceTable(Tablenum(SalesTable)).addRange(fieldNum(SalesTable,RecId)).value(SysQuery::value(conPeek(con,i)));
    }
} 

Hope it helps.

Taken from Ax-Forum

Compare answered 10/4, 2015 at 8:28 Comment(3)
Thanks fr your help Nadeem_MK,Zenobiazeolite
Thanks fr your help Nadeem_MK, whith your code i give more records from first from(A) but i have in both dataSource Form my SalesTable? I have a easy question, where i have to fill my stringEdit in second form(B)? I need to pute code look like in secondform(B): stringEdit.text(SalesTable.field);Zenobiazeolite
Thanks. I don't understand the question properly but if you need to set the data / manipulate the record, you will need to put it in the loop itself. Between for(i = 1;i<= conLen(con) ;i++) {Compare
F
3

This will typically imply looping through the selected records in Form-A and changing the query in Form-B.

The idiomatic way to loop through selected records involves a for loop and the getFirst and getNext methods of the datasource:

SalesLine sl;
FormDataSourcs ds = _salesLine.dataSource();
for (sl = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor(); sl; sl = ds.getNext())
{       
    //Do your thing, add a query range
}

The MultiSelectionHelper class may be of use here, as it does the thing:

public void init()
{
    MultiSelectionHelper ms;
    super();       
    if (element.args() && element.args().caller() && element.args().record())
    {
        this.query().dataSourceTable(tableNum(SalesLine)).clearDynalinks();
        ms = MultiSelectionHelper::createFromCaller(element.args().caller());        
        ms.createQueryRanges(this.query().dataSourceTable(tablenum(SalesLine)), fieldstr(SalesLine, InventTransId));
    }
}
Fallacious answered 10/4, 2015 at 8:38 Comment(1)
A better example using MultiSelectionHelperElbertine

© 2022 - 2024 — McMap. All rights reserved.