Add Custom Parameter to Strategy Call
You have learned how to pass existing parameters to your logic, but you may want to add some other factors/parameters which are not available out-of-the-box.
Let’s add our own custom simple parameter:
Modify Strategy Calculation Parameters to pass one more parameter to our calculation method call:
Navigate to the Company Parameter StrategyDefinition.
In definition of your strategy TrainingCost+, set the value for the Strategy Calculation Parameters field to "PRODUCT_COST,OWN_PARAMETER".
Modify the implementation of your strategy to accept one more parameter – we call it ownParameter.
Map calculatePrice ( BigDecimal cost, BigDecimal ownParameter ) { BigDecimal price = cost + ownParameter return [ result : price, message : "OK", messageType : "Info" ] }
Add implementation of the custom parameter:
Find logic ParentPriceListLogic which is part of Price Setting Accelerator installation which you have on your partition.
The same element exists in DependentPriceListLogic and it works exactly the same, but in this article we are focusing only on the parent one.
Review the code of the element AdditionalCalculationParameters. It defines a map, used for additional custom parameters. It is explained in detail inside the element. The key should be used for static values like constants that are already available in the calculation logic and it should be used also for any dynamic parameters because they are lazy loaded only when an engine using them is being used. The value must be a Closure.
Modify the definition of AdditionalCalculationParameters to provide a Closure value for OWN_PARAMETER.
return out.WarningManager.tryToExecuteElement("AdditionalCalculatorParameters") { return [OWN_PARAMETER: {return 10}] }
Deploy the change.
Recalculate the product item in your Live Price Grid, and:
Show the Prices field to see if the result of your strategy calculation is displayed correctly.
Review the fields Cost and Final Price to see if the calculation is done as expected.
Â
Previous step: Add Built-in Parameter to Strategy Call
Â
Conclusion
Now you know how to create your own custom strategy, how to pass parameters between Pricefx Studio and your Pricefx partition and how to create additional parameters that you can define through StrategyDefinition.
Additionally, you have learnt that if you need more control over messages (both info and error messages), you can return a more complex map structure with info, warning and critical types of messages.
You have also learnt where to find the libraries that drive the calculation engines and can select from out-of-the-box libraries within Pricefx Studio CalculationEnginesLib or create your own.