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
Create a new action (equations script) “CALCULATE_VALUE_EQ” and specify this script:
using System;
using System.Collections.Generic;
using Formation.Shared.Defs;

class EquationScript : FcProcFuncSetEQFunction
{
    public long evaluate()
    {
        long rc = 1L;

        try
        {
            // Deserialize JSON equation parameters into a dictionary
            Dictionary<string, object> jsonObj = Deserialize<Dictionary<string, object>>(Context.EquationParams);

            // Safely extract the parameter value (key: "PARAM_NAME")
            object parameter = null;
            if (jsonObj != null && jsonObj.ContainsKey("PARAM_NAME"))
            {
                parameter = jsonObj["PARAM_NAME"];
            }

            // Provide implementation for the equation
            string calculatedValue = "20";

            // Set the equation return value (string as in original VB)
            Context.ReturnValue = $"Symbol:{Context.ObjectSymbol} Key:{Context.ObjectKey} Parameter: {parameter} Value: {calculatedValue}";
        }
        catch (Exception ex)
        {
            // Log error (MessageList is commonly available in workflow/equation context)
            MessageList("Equation error: " + ex.Message);
            rc = 0L;
        }

        return rc;
    }
}
Step 2:
using System;
using System.Diagnostics;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // Format JSON input for the equation
        string formattedJson = string.Format("{{\"Symbol\": \"{0}\", \"ObjectKey\": \"{1}\", \"EquationParams\": {{\"PARAM_NAME\": \"COST\"}}}}", _OBJECTSYMBOL, _OBJECTKEY);
        
        // Call the equation
        string value = EvaluateEquation("CALCULATE_VALUE_EQ", formattedJson);
        
        // Display results
        MessageList(_OBJECTSYMBOL);
        MessageList(_OBJECTKEY);
        MessageList(formattedJson);
        MessageList(value);
        
        return 0;
    }
}
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.ReturnValue to 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 MessageList and the string returned by EvaluateEquation.
  • EquationScript.evaluate inputs: Context.EquationParams (string JSON), Context.ObjectSymbol, Context.ObjectKey.
  • EquationScript outputs: Context.ReturnValue (formatted string) and return status (1L success / 0L failure).