Friday, 12 October 2018

Passing values between pre and post event handlers in D365FO / AX 7

Here is the sample code to pass / store values between pre and post event handlers using args. You can set the value in pre-event handler using args.addArg and get the value in post handler args.getArg.


    /// <summary>
    /// enforcePayRateTolerance pre event handler
    /// </summary>
    /// <param name="args">Event args</param>
    [PreHandlerFor(tableStr(HRMCompFixedPlanTable), tableMethodStr(HRMCompFixedPlanTable, enforcePayRateTolerance))]
    public static void HRMCompFixedPlanTable_Pre_enforcePayRateTolerance(XppPrePostArgs args)
    {
        HRMCompFixedPlanTable HRMCompFixedPlanTable = args.getThis();

        args.addArg("Tolerance", HRMCompFixedPlanTable.Tolerance);

        HRMCompFixedPlanTable.Tolerance = HRMCompTolerance::None;
    }

    /// <summary>
    /// enforcePayRateTolerance post event handler
    /// </summary>
    /// <param name="args">Event args</param>
    [PostHandlerFor(tableStr(HRMCompFixedPlanTable), tableMethodStr(HRMCompFixedPlanTable, enforcePayRateTolerance))]
    public static void HRMCompFixedPlanTable_Post_enforcePayRateTolerance(XppPrePostArgs args)
    {
        HRMCompFixedPlanTable HRMCompFixedPlanTable = args.getThis();
        HRMCompTolerance tolerance;

        if (args.existsArg("Tolerance"))
        {
            tolerance = args.getArg("Tolerance");

            HRMCompFixedPlanTable.Tolerance = tolerance;
        }
    }

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...