Predefined Variables
There are some predefined variables that are already initialized and shared across custom logic.
quoteProcessor – Pricefx predefined processor available in the quote header context and already bound to your custom library as a predefined variable. It can be accessed from all contexts.
elements – Map containing previous logic results. It can be accessed from all contexts.
header – Map containing header processed results. This variable can be accessed in the inputs and outputs generation context.
lineItem – Current processing line item. This variable can be accessed in the inputs and outputs generation context.
inputs - Current processing line item input values. This variable can be accessed in the inputs and outputs generation context.
inputConfig – Current processing input configuration. We can use this to update the current input config. This variable can be accessed in the inputs generation context.
outputs – Current processing line item outputs values. This variable can be accessed in the inputs and outputs generation context.
outputConfig – Current processing output configuration. We can use this to update the current output config. This variable can be accessed in the outputs generation context.
The predefined variable can be accessed either by its name or TaskProcessor.
name
From version 2.0.3, this is only available when predefinedBindingAsScriptProperty
configuration is enabled.
function myElement(){
// previous element name from PP table is “myCustomQuantity”
def quantity = elements.myCustomQuantity
return quantity
}
TaskProcessor
function myElement(){
// previous element name from PP table is “myCustomQuantity”
Map elements = libs.CPQ_SharedLib.TaskProcessor.getProcessingBinding("elements")
def quantity = elements.myCustomQuantity
return quantity
}
The predefined variables are automatically injected into the custom library. This can slow down the process. In version 2.0.3, a new configuration named predefinedBindingAsScriptProperty
is added and enabled as default. So you can decide whether to inject those variables automatically or not.
If it is disabled, you cannot use predefined bindings directly; a quick fix is to wrap the method implementation under libs.CPQ_SharedLib.TaskProcessor.runWithPredefinedBindings
.
// When 'predefinedBindingAsScriptProperty' is enabled
BigDecimal execute() {
boolean isPriceInput = libs.CPQ_Output_Utils.Common.isPriceInput()
// 'header' is predefined binding. You can access it directly in custom library as it is injected automatically
BigDecimal priceFromLookup = header.ProductPrices?.getAt(lineItem.sku)?.resultPrice
return isPriceInput ? BigDecimal.ZERO : priceFromLookup
}
// When 'predefinedBindingAsScriptProperty' is disabled
BigDecimal execute() {
// 'header' is predefined binding. You cannot access it directly in custom library as it is not injected automatically.
// A quick fix is to wrap the implementation under "libs.CPQ_SharedLib.TaskProcessor.runWithPredefinedBindings"
return libs.CPQ_SharedLib.TaskProcessor.runWithPredefinedBindings {
boolean isPriceInput = libs.CPQ_Output_Utils.Common.isPriceInput()
BigDecimal priceFromLookup = header.ProductPrices?.getAt(lineItem.sku)?.resultPrice
return isPriceInput ? BigDecimal.ZERO : priceFromLookup
}
}