Event Handler Result in D365 AX

Hi,

Event Handler Result in D365 AX -- Access result of one model from other model.

Use of delegates is a situation when you want to access a code from another model without referencing it, for example accessing the code in a higher model from a lower model.

Sample Delegate code

Want to stop updating price for already been created sales lines in SO.

I have added new delegate in SalesLine Method

Sales Line Method

 delegate void BlockPriceRefresh(SalesLine saleslinePricePreserv,EventHandlerResult _res)
    {

    }

public void setPriceAgreement(
        InventDim _inventDim,
        boolean _doCallPriceDate = false,
        PriceDiscPolicyCheckPolicy  _checkPolicy = null,
        boolean _initDateFields = true)
    {

        EventHandlerResult result = new EventHandlerResult();
       //Calling event handler 
        this.BlockPriceRefresh(this, result);

        boolean res = result.result();

        //Block Price refresh if its enabled in custom model settings in site.
        if(res==false)
        {
        this.SalesPurchLine::setPriceAgreement(_inventDim, _doCallPriceDate, _checkPolicy, _initDateFields);
        }

    }

Add new class and subscriber for above delegate and return result based on condition in Custom Model to standard model

[SubscribesTo(tableStr(SalesLine), delegateStr(SalesLine, PreservPriceRefresh))]
    public static void SalesLine_BlockPriceRefresh(SalesLine saleslinePricePreserv,EventHandlerResult _res)
    {
        //- Block Sales price refresh by Custom Field SalesPriceRefresh
        if(saleslinePricePreserv.RecId && InventSite::find(saleslinePricePreserv.salesTable().InventSiteId).SalesPriceRefresh)
        {
            _res.result(true);
        }
        else
        {
            _res.result(false);
        }
        //    //<-- Block Sales price refresh


    }


REFERENCE



Comments

Post a Comment