1
votes

I have a custom plugin I've created that calculates tax automatically on a Quote Product (entity.LogicalName = quotedetail). It takes the amount field (BaseAmount), the manual discount field (ManualDiscountAmount) and a custom 'Tax Percent' field (new_UKTaxPercent). The math is pretty simple ((BaseAmount - ManualDiscountAmount) / 100 * new_UKTaxPercent).

My plugin fires 2 steps, first on the create message to initialize the variables and set the tax percentage field to 20 and then on the update message to calculate the tax based on the values passed into the context after the entity is created.

The tax field calculates and sets after the plugin runs for the first time, however, if I then modify the manual discount amount, the tax is not recalculated. It is however, if I modify the amount field.

I have a Post Operation Create step that includes a Post Image called postImage and a Pre Operation Update step that fires after the Create step with a Pre Image called preImage:

My question is simply, why doesn't the update of the manual discount field trigger the update of the tax field but the update of the amount field does?

Edit: Screenshots of the update step added below on request

enter image description here Fig 1: Update step

enter image description here Fig 2: Image step

Thanks in advance

1
If the update fires on some but not all fields, you should firstly check on which attributes your step is selected to run. You can see this under properties for the selected step. You can select there on which attributes the plugin should fire. Do NOT select all attributes as when you update one of the fields, the plugin step may enter a recursive call.Bojan Borisovski
Hi Bojan, The fields I have selected in the update step are (baseamount, manualdiscountamount, tax, new_uktaxpercent) and this matches with the fields selected in the pre-image.eredn_
I Agree with @BojanBorisovski. If it's firing in one case, and not the other, it's most likely the registration. Maybe posting a screen shot of the plugin registration tool for the update event?Daryl
Hi Daryl, I've added screenshots for you. I've also added the following line of code to the bottom of my plugin that updates the description field with the Manual Discount Amount.... currentEntity.Description = _manualDiscountD.ToString(); which returns 0.00 - so the update step is definitely not passing the data througheredn_
Can you verify if the plugin is firing at all on manualdiscountamount change by inserting an exception or something similar?Rickard N

1 Answers

0
votes

Geez, I've managed to do it. All I did to get this working was to change the Entity Alias field of the preImage step to preImage. Plugin now updates tax field based on value entered into the manual discount field too :)

I am one happy guy.

Thanks to Rickard for his input and to all others who contributed.