Showing posts with label d365 eventhandler. Show all posts
Showing posts with label d365 eventhandler. Show all posts

Tuesday, 26 November 2019

d365 eventhandler insert method table DataEventType::Inserting D365 Code

Below is the event handler code to write at the table level for inserting any value.

  [DataEventHandler(tablestr(FMRentalCharge),DataEventType::Inserting),
   SuppressBPWarningAttribute('BPParameterNotUsed', 'This is not production code')]
   public static void FMRentalChargeInsertingEvent(Common c, DataEventArgs e)
    {
        FMRentalCharge rentalCharge = c;
        FEDiscountEngine discountEngine;

        discountEngine = FMTotalsEngineBase::GetInstance() as FEDiscountEngine;
        if (discountEngine)
        {
            discountEngine.calculateChargeRate(rentalCharge);
        }
    }

FMRentalChargeInsertingEvent -> you can write any name .
SuppressBPWarningAttribute - > is optional( it is for not using the e parameter of the dataeventargs.)

update method d365 eventhandlertable DataEventType::Updating D365 Code

Below is the event handler code to write at the table level for Updating any value.

Eventhandler code for updating a value at the table level .

[DataEventHandler(tablestr(FMRentalCharge),DataEventType::Updating),
     SuppressBPWarningAttribute('BPParameterNotUsed', 'This is not production code')]
    public static void FMRentalChargeUpdatingEvent(Common c, DataEventArgs e)
    {
        FMRentalCharge rentalCharge = c;
        FEDiscountEngine discountEngine;

        if (rentalCharge.orig().PerUnitAmount != rentalCharge.PerUnitAmount ||
            rentalCharge.orig().Quantity != rentalCharge.Quantity)
        {
            discountEngine = FMTotalsEngineBase::GetInstance() as FEDiscountEngine;
            if (discountEngine)
            {
                discountEngine.calculateChargeRate(rentalCharge);
            }
        }
    }

FMRentalChargeUpdatingEvent-> you can write any name .
SuppressBPWarningAttribute - > is optional ( it is for not using the e parameter of the dataeventargs.

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...