Set Messaging from Calculation Logic
There are two types of results to be returned – you can find out more about that in Custom Engines. What we returned right now is a big decimal with a price.
When we cannot calculate and return a price, we can report the problem from the logic:
Throw an exception with an error message.
The reason message will be displayed as white text on a red background.
Return a more detailed result with a message and type.
The reason message will show the provided message, and you will see the message type with an appropriate color on the side.
This could be used, for example, when calculating a competition based price. We can return the name of the competitor or any other information the pricing manager may need to understand the calculated price.
Add the messaging to your implementation:
Change the implementation of your engine to:
Map calculatePrice() { //❶ return [ price : 5.0, message : "This is the message", messageType : "Warning" //❷ ] }
❶ Watch out – the returned type is Map.
❷ For possible message types, see Custom Engines.Remember to deploy the modified logic.
Recalculate the product in the Live Price Grid.
Review the results in the column Prices, and make sure that you see not only the price but also the message with the right color.
Previous step: Test Calculation using Custom Pricing Strategy
Next step: Add Built-in Parameter to Strategy Call