Custom Price Calculations in CRM 2015: A Game Changer for Complex Pricing Needs
In our previous discussions, we’ve covered the enhancements made to the Product Catalog in Microsoft Dynamics 365 CRM. In this post, we’ll dive into the Custom Price Calculation feature, which builds on these catalog improvements.
While Microsoft Dynamics CRM has always supported standard pricing and discounting methods, these built-in fields can sometimes fall short when businesses need more advanced rules, such as specific taxation, discounts, or unique pricing scenarios for their products.
Let’s take a closer look at a scenario where businesses need to apply multiple types of taxes—like GST, VAT, Stamp Duty, or state and federal taxes—independently for each line item. This was a tricky task in previous versions of Dynamics CRM due to the limitation of only one Tax field per line item. Creating custom fields for each additional tax was possible, but it complicated the process of calculating the Extended Amount for each item.
How CRM 2015 Simplifies Custom Price Calculations
With CRM 2015, you can now apply Custom Price Calculations to the following entities:
- Opportunity
- Opportunity Product
- Quote
- Quote Product
- Order
- Order Product
- Invoice
- Invoice Product
This feature gives you the flexibility to calculate prices, taxes, and totals exactly the way you need. To enable custom pricing for your opportunities, quotes, orders, and invoices, follow these steps:
Steps to Enable Custom Price Calculation
1. Disable Out-of-the-Box Pricing
Set the OOBPriceCalculationEnabled attribute to false in the system settings, as shown below. .
2) Create a Custom Plug-In
Write a plug-in containing your custom logic for calculating prices on your opportunities, quotes, orders, or invoices, and for each corresponding line item.
3) Register the Plug-In
Register the plug-in on the CalculatePrice message at the Post stage.
When the OOBPriceCalculationEnabled attribute is set to false, every time an opportunity, quote, order, or invoice is created or updated, the plug-in will trigger, calculating prices based on the logic you’ve defined. The CalculatePriceRequest message has no predefined use case—it’s simply there to allow you to integrate your custom pricing logic, should you choose not to use the out-of-the-box pricing engine.
If you ever want to revert to the default pricing logic, simply set the OOBPriceCalculationEnabled attribute back to true.
Real-World Example: Calculating GST and VAT
Let’s look at a real example. Suppose we need to apply GST and VAT to calculate the Extended Amount on a Quote Product.
In the plug-in, we use the following logic to calculate the taxes based on the amount, ensuring they’re included in the final Extended Amount:
decimal total = 0;
decimal vat = 0;
decimal gst = 0;
decimal extended = 0;
total = total + ((decimal)e[“quantity”] * ((Money)quoteItem[“priceperunit”]).Value);
gst = total * (decimal)0.08;
vat = total * (decimal)0.1;
extended = total + gst + vat;
quoteItem[“baseamount”] = new Money(total);
quoteItem[“tax”] = new Money(gst);
quoteItem[“new_vat”] = new Money(vat);
quoteItem[“extendedamount”] = new Money(extended);
service.Update(quoteItem);
In this example, the GST is calculated as 8% of the total, and the VAT is calculated as 10% of the total. The ExtendedAmount field includes both taxes.
We registered this plug-in on the Post stage of the CalculatePrice message for the Quotedetail, ensuring that the custom pricing logic runs whenever the quote is created or updated.
Using Microsoft’s Sample Plug-In
To save time and make implementation smoother, you can leverage the sample plug-in provided by Microsoft. This can serve as a great starting point for your custom price calculation implementation. You can find the sample plug-in at the following URL:
Key Considerations for Custom Price Calculations
- OOBPriceCalculationEnabled must be set to false to enable custom pricing.
- The plug-in needs to be registered on the Post stage of the CalculatePrice message.
- Once custom pricing is enabled, the Amount and Extended Amount on line items (and all header totals) will no longer be automatically calculated by the system. Your plug-in will be responsible for these calculations.
- One important thing to note: Custom pricing calculations are processed asynchronously. This means that after changing the price or quantity in line items, you may need to refresh the form to see the updated values.
Conclusion
Custom Price Calculations in CRM 2015 give businesses the flexibility to apply complex pricing rules tailored to their unique needs. Whether you’re handling multiple taxes, applying specific discounts, or calculating special pricing based on specific business rules, this feature makes it easier to get the results you need.
If you’re ready to implement custom pricing or have any questions, feel free to reach out to us. We’d love to help!