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:

  1. Modify Strategy Calculation Parameters to pass one more parameter to our calculation method call:

    1. Navigate to the Company Parameter StrategyDefinition.

    2. In definition of your strategy TrainingCost+, set the value for the Strategy Calculation Parameters field to "PRODUCT_COST,OWN_PARAMETER".

  2. 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" ] }
  3. Add implementation of the custom parameter:

    1. Find logic ParentPriceListLogic which is part of Price Setting Accelerator installation which you have on your partition.

      1. The same element exists in DependentPriceListLogic and it works exactly the same, but in this article we are focusing only on the parent one.

    2. 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.

    3. Modify the definition of AdditionalCalculationParameters to provide a Closure value for OWN_PARAMETER.

      return out.WarningManager.tryToExecuteElement("AdditionalCalculatorParameters") { return [OWN_PARAMETER: {return 10}] }
    4. Deploy the change.

  4. Recalculate the product item in your Live Price Grid, and:

    1. Show the Prices field to see if the result of your strategy calculation is displayed correctly.

    2. Review the fields Cost and Final Price to see if the calculation is done as expected.

 

Previous step:

 

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.