You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CRM has a message called CalculatePrice which calculates the price on the following 8 entities:
quote
quotedetail
opportunity
opportunityproduct
salesorder
salesorderdetail
invoice
invoicedetail
The documentation on this message and logic behind it is extremely limited.
It is possible to overwrite this feature in CRM and implement a plugin that listens on this message. As a part of a solution I had to deliver I had to overwrite the standard out-of-box solution. Which is why I have managed to understand this feature somewhat.
The (somewhat) useful documentation I have found are the following:
Sample: Calculate Price plug-in: Microsofts documentation on writing a plugin for overwriting the build in PriceCalculation. However, this is severely lacking in proper plugin execution as its method for avoiding infinite call of the plugin is outdated and not supported anymore. The plugin also causes unnecessary recursive execution of the plugin
Dynamics CRM 2015 Custom Price Calculation: A blog showing a much better implementation, but still far from usable. The useful part is that it is a recreation of the out-of-box solution.
Everything else is by trial an error.
So how does CalculatePrice work?
The CalculatePrice message is called whenever one of the eight entities is retrieved. There are in general two parts to the calculation. Calculation of the four detail/product entities and calculation of the four main entities.
The calculation of the detail/product only calculates everything related to them self while the four main entities calculates for both the detail/product related to the entity and the entity itself.
An incorrect implementation will try to retrieve either of the eight entities within the plugin execution more than necessary. This will cause the CalculatePrice message to be called again and the plugin will be executed again. This is not 100% avoidable as you have to retrieve the related detail/product when working with the main entity. For my custom solution of the PriceCalculation I have added a depth limit of 5 on the plugin. I believe that it can be done with 4 and still produce the correct solution.
An additional problem is that the main entity and detail/product entity can not be update when the main entity is either deactivated or the price is locked.
To help mitigate the need for retrieving information on the main entity when working with the detail/product entity. Two additional attributes are available on the detail/product entity defining the state and if the price is locked on the main entity. (e.i. the invoicedetail entity has two attribute called invoicestatecode and invoiceispricelocked)
As far as I know, Mockup does no updates either of these two attributes on any of the four detail/product entities. Which means that this should be implemented first.
Required to implement this feature:
Implement the Calculate Price request on retrieve on any of the eight entities
Implement system plugin that updates the _statecode and _ispricelocked on the four detail/product entities when the main entity state changes or the price is locked
Implement Price Calculation of the eight entities
Add an option to XrmMockupSetting to either use Mockups PriceCalculation or custom PriceCalculation plugin. The same way the it can be done in CRM
I will recommend that the solution is added as system plugins that Mockup calls instead of implementing as part of Mockup main logic.
I have attached two files with the code I have previously made to overwrite PriceCalculation in CRM. This code implements the danish taxing system instead of the default US standard that CRM uses.
CRM has a message called CalculatePrice which calculates the price on the following 8 entities:
The documentation on this message and logic behind it is extremely limited.
It is possible to overwrite this feature in CRM and implement a plugin that listens on this message. As a part of a solution I had to deliver I had to overwrite the standard out-of-box solution. Which is why I have managed to understand this feature somewhat.
The (somewhat) useful documentation I have found are the following:
Everything else is by trial an error.
So how does CalculatePrice work?
The CalculatePrice message is called whenever one of the eight entities is retrieved. There are in general two parts to the calculation. Calculation of the four detail/product entities and calculation of the four main entities.
The calculation of the detail/product only calculates everything related to them self while the four main entities calculates for both the detail/product related to the entity and the entity itself.
An incorrect implementation will try to retrieve either of the eight entities within the plugin execution more than necessary. This will cause the CalculatePrice message to be called again and the plugin will be executed again. This is not 100% avoidable as you have to retrieve the related detail/product when working with the main entity. For my custom solution of the PriceCalculation I have added a depth limit of 5 on the plugin. I believe that it can be done with 4 and still produce the correct solution.
An additional problem is that the main entity and detail/product entity can not be update when the main entity is either deactivated or the price is locked.
To help mitigate the need for retrieving information on the main entity when working with the detail/product entity. Two additional attributes are available on the detail/product entity defining the state and if the price is locked on the main entity. (e.i. the invoicedetail entity has two attribute called
invoicestatecode
andinvoiceispricelocked
)As far as I know, Mockup does no updates either of these two attributes on any of the four detail/product entities. Which means that this should be implemented first.
Required to implement this feature:
_statecode
and_ispricelocked
on the four detail/product entities when the main entity state changes or the price is lockedI have attached two files with the code I have previously made to overwrite PriceCalculation in CRM. This code implements the danish taxing system instead of the default US standard that CRM uses.
The text was updated successfully, but these errors were encountered: