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

Update Values During Data Entity Import in D365FO

Update Values During Data Entity Import in D365FO Updating Field Values During Data Entity Import in Dynamics 365 Finance ...