EvaluateEquation
You can use the EvaluateEquation function to execute an equation dynamically using an API by passing an equation code and input parameters in JSON format. The equation processes the input and returns the calculated result.
When to use
You can use this function when:
- You need to execute complex calculations dynamically from workflows or actions without hardcoding the calculation logic.
- To enable external systems or workflows to execute Optiva equations programmatically via API calls.
When not to use
You must not use this function in tight loops because calling equations has processing overhead. You must use direct calculations.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| equationCode | string | Yes | The code of the equation to execute. For example, "CALCULATE_VALUE" |
| inputJSON | string | Yes | The JSON string containing input parameters for the equation including Symbol, ObjectKey, and EquationParams. |
JSON Format Example
"Symbol": "ITEM", "ObjectKey": "ITEM-001", "EquationParams": { "PARAM_NAME": "COST", "OTHER_PARAM": "VALUE" } }
Return Value
The application returns the result of the equation as a string when the equation is completed successfully.
Prerequisites
You must specify all required fields in EquationParams.
Examples
- Example 1
- Step 1: Deserialize JSON params and return formatted result
- Description
-
A paired Action(action script + equation) example that demonstrates a workflow action (ActionScript.wf_start) building a JSON payload containing the current object Symbol or ObjectKey and an EquationParams object (PARAM_NAME = "COST"), calling an equation by code ("CALCULATE_VALUE") via
EvaluateEquation, and logging the request and response.The equation implementation (EquationScript.evaluate) deserializes the incoming JSON (Context.EquationParams), extracts PARAM_NAME, computes or looks up a value (here a placeholder "20"), sets
Context.ReturnValueto a formatted result including Symbol, ObjectKey, Parameter and Value, and returns a status code.
Inputs/Outputs
- ActionScript.wf_start inputs: workflow context variables _OBJECTSYMBOL, _OBJECTKEY; no external params required in this example.
- ActionScript outputs: logs via
MessageListand the string returned byEvaluateEquation. - EquationScript.evaluate inputs: Context.EquationParams (string JSON), Context.ObjectSymbol, Context.ObjectKey.
- EquationScript outputs:
Context.ReturnValue(formatted string) and return status (1L success / 0L failure).