Thursday, May 19, 2022

x++ code to get all selected records from form datasource or Grid

Hi All,
In this blog we will learn how to get all selected records from form grid or form datasource in event handler.    

X++ code.

[FormControlEventHandler(formControlStr(LedgerJournalTransCustPaym, UpdateOffsetDimension), FormControlEventType::Clicked)]

public static void UpdateOffsetDimension_OnClicked(FormControl sender, FormControlEventArgs e)
{
        FormRun                 formRun     = sender.formRun();
        FormDataSource          ledgerJournalTrans_ds;
        LedgerJournalTrans      ledgerJournalTrans;        
        ledgerJournalTrans_ds = formRun.dataSource(tableStr(LedgerJournalTrans));

        MultiSelectionHelper    selectionHelper = MultiSelectionHelper::construct(); 

        selectionHelper.parmDataSource(ledgerJournalTrans_ds); 

        ledgerJournalTrans = selectionHelper.getFirst();

        while (ledgerJournalTrans)
        {
            info(ledgerJournalTrans.Voucher);
            ledgerJournalTrans = selectionHelper.getNext();
        }
}

1 comment:

  1. Thank you for your great contribution and if I only want all the records of the grid, since it is disabled to be able to select several

    ReplyDelete

How to Post Partial Product Receipt in D365FO Using X++ Code

How to Post Partial Product Receipt in D365FO Using X++ Code How to Post Partial Product Receipt in D365FO Using X++...