Formula

The Formula node allows the workflow to make decisions automatically, without action being taken by a user. The node executes code written in JavaScript to determine which connector to follow. The JavaScript code uses an implicitly available object named form that acts as the interface to the workflow.

The form object provides access to the values of controls in the form. The access is provided using the method value ( <name> ), where <name> is the name of a control in the interaction whose value is retrieved. This method returns the value of the control name passed in as a string.

The form object also has a branch property that the JavaScript code must set to indicate which branch to traverse. If a branch is not selected, the system generates an exception. The branch property must be set to the name of a Connector for that connector to be traversed.

For example, when an expense form is submitted, a Formula can calculate whether the total expense amount exceeds a threshold, then forward the request to the appropriate user in the workflow:

var nClaimAmount = 1 * form.value( "ClaimAmount" );
if ( nClaimAmount >= 1000 ) {
form.branch = "send to manager";
} else {
form.branch = "send to finance dept";
}

Information from the database can be read from the Formula node in the Workflow Editor. This is performed through the implicit variable "db". For example, the statement block below retrieves employee data for consumption:

try
{
// execute a query against the database
db.executeQuery( "select EMP_ID, EMP_NAME from EMPLOYEE" );
// loop through each line of the results
while ( db.next() )
{
// get values in this row
var empId = db.getString( "EMP_ID" );
var empName = db.getString( "EMP_NAME" );
}
}
finally
{
// close the connection and related objects
db.close();
}

You can also use the runUpdateQuery( <query> ) function that allows a formula node in the workflow to interact with the database. An update or insert query between the quotes is executed when the node is processed:

var sql =
"update CUSTOM_TABLE set " +
"CUSTOM_FIELD='" + form.value( "XXXX" ) + "' ";

In addition to the above, all other functions and control structures from the JavaScript language are supported. Additional help for these is available in the Formula Editor window (double-click the Formula node icon to open), by clicking the drop-down lists under Statements, Top-Level Properties and Functions, and Core Objects. In addition to descriptions, this interactive help can also insert code templates directly into a Formula.

Property Description Sample Value Mand-atory or Optional Notes
Description Brief description of the node. Form encountered an exception. Optional
Formulas Use the Formula Editor to add the formula to the control.

The Formula node accepts JavaScript formulas. The JavaScript code of the formula nodes contains an implicit form object that acts as the interface to the workflow engine.

See Above Mandatory The RunUpdateQuery(" ") function enables you to update fields and tables in a database from a formula node in the workflow. Add the update query between the quotes to directly update the database when the node is processed.
Icon The *.GIF image that represents the Formula icon. formula.gif Mandatory Defaults to formula.gif.
Name Name assigned to the icon. The name is displayed directly underneath the icon in the workspace. The name assigned should be relevant to the node purpose. Formula1 Mandatory Defaults to <node name> and the number, which increments based on the number of current nodes being added. For example, if this control is the fifth Formula node being added to the workflow, the node Name would be Formula5.