Friday, 27 July 2018

How to get multiple selected records in control level event handlers in D365FO / AX 7

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.

/// <summary>
/// The <c>HRPayrollPayStatementEventHandler</c> class is the event handler class for managing PayrollPayStatement form events
/// </summary>
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();
            }          
        }
    }
}

No comments:

Post a Comment

Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...