Showing posts with label how to pass multiple selected records. Show all posts
Showing posts with label how to pass multiple selected records. Show all posts

Sunday, May 18, 2014

Pass multiple records from one form to another

I came across a requirement to pass multiple records from one form to another. It might would be a very common practice now. However, I thought to blog it for if anyone still not cleat with this part.


Instead of passing datasource as an argument in the property, Override clicked() method of button and prepare your args to pass as shown. I am taking an example of SalesTable to pass to another form

void clicked()
{
    int         recordsCount;
    SalesTable  salesTable;
    container   con;
    Args        args;
    str         multiSelectString;

    args = new Args();
    // 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);

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

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

Now in the above method we have already prepared our args in a container and have passed that to a new form of menu item "NewFormMenuItem"

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;
    str         multipleRecords;
   
    super();
   
    // to get string value from caller
    multipleRecords = element.args().parm();

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

    // 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)));
    }
} 

If you have some more improved versions of this task please share.
Happy DAXing!