D365 / AX – X++ – How to get multiple selected records in control level event handlers

Purpose:
The purpose of this document is to show how to get multiple selected records in form control event handlers.

Development:
First of all create new event handler class HRPayrollPayStatementEventHandler and subscribe to form button OnClicked event handler.

/// /// The HRPayrollPayStatementEventHandler class is the event handler class for managing PayrollPayStatement form events ///
class HRPayrollPayStatementEventHandler
{

/// <summary>
/// Click event handler
/// </summary>
/// <param name="_sender">Form control buffer</param>
/// <param name="_e"> Event args</param>
[FormControlEventHandler(formControlStr(PayrollPayStatement, CustomButton), FormControlEventType::Clicked)]
public static void SLD_CustomButton_OnClicked(FormControl _sender, FormControlEventArgs _e)
{
    FormDataSource    PayrollPayStatement_DS = _sender.formRun().dataSource(formDataSourceStr(PayrollPayStatement, PayrollPayStatement));

    MultiSelectionHelper    selectionHelper = MultiSelectionHelper::construct();
    PayrollPayStatement     payStatement;

    selectionHelper.parmDataSource(PayrollPayStatement_DS);
    payStatement  = selectionHelper.getFirst();

    if (payStatement.RecId)
    {
        while (payStatement.RecId != 0)
        { 
            info (payStatement.DocumentNumber);

            payStatement = selectionHelper.getNext();
        }          
    }
}

}

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...