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

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

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;

    payStatement  = selectionHelper.getFirst();

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

            payStatement = selectionHelper.getNext();


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s