Search code examples
reportaxapta

Retrieve records in report from multiple selection ax


I have a question regarding on how to retrieve the records that I have selected in a form, to a report.

Currently, I am able to select multiple records, but when it comes to the report, it keep on processing the same value. However the number of the records that it processed is correct, only the value is repeating.

I am not sure on how to fix this, therefore your help is kindly appreciated.

Below is the part that i get the record:

if (element.args() && element.args().dataset())
{
    switch(args.dataset())
    {
        case tablenum(LedgerJournalTrans) :
            ledgerJournalTrans = element.args().record();
            info(ledgerJournalTrans.Voucher);
            break;    
        case tablenum(LedgerJournalTable) :
            ledgerJournalTable = args.record();
            break;
    }    
}

Solution

  • The element.args().record() only points to the last selected record. Its datasource comes to rescue. The usual approach to process multi-selected records applies:

    Common record;
    FormDataSource fds;
    fds = element.args().record().dataSource();
    for (record = fds.getFirst(1) ?  fds.getFirst(1) : fds.cursor(); record; record = fds.getNext())
    {
         // Do the printing using record
    }
    

    You often see this approach used in main methods of functions capable of processing multi-selected records.

    The FormLetter.getFormRecord uses this pattern as well.