Showing posts with label Adding args in event handlers in ax. Show all posts
Showing posts with label Adding args in event handlers in ax. Show all posts

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;
        }
    }

Run AX report using X++

       Args                     args;      ReportRun          report;     salesLineProductPartProd salesLineProductPartProdLocal;     ;     ...