Script Language

Contents

Script Language Usage

  • Flow and Nodes Conditions
  • Access Rules Conditions
  • Assignment Rules

Syntax

Basic Expression Syntax

Basic Syntax of Omni-Expression is a single expression; same as that of “Symfony Expression Language”

 age>25 && carType=='Sports'

Script Syntax

Comments

Comments are included between /* and */ tags

Variable definition and Assignments

variables can be assigned values, if the variable does not existed it will be created.

variable1='abc';
/* new variable is now declared with value 'abc' */

Multi-Statements separated by ‘;’

Scripts can contain multiple statements with ‘;’ separator

variable1='abc';
variable2='zyz';
log('testing for variables '~variable1~' and '~variable2);

Conditional Logic

If (expression) { true logic } else {  false logic}
if (amount>500)
{
return(true);
}
else
{
return(false);
}

While
while (counter <10 )
{
if (condition)
break;
counter++;
}

foreach

foreach ( arrayVariable as var  )

{

… place logic here

if (condition)

break;

if (condition)

continue;

 

}

Supported Literals

The component supports:

  • strings – single and double quotes (e.g. 'hello')
  • numbers – e.g. 103
  • arrays – using JSON-like notation (e.g. [1, 2])
  • hashes – using JSON-like notation (e.g. { foo: 'bar' })
  • booleanstrue and false
  • nullnull

Working with Objects

When passing objects into an expression, you can use different syntaxes to access properties and call methods on the object.

The following Objects are available to all Expressions

object name Description
_case The current Workflow Case
_context contains information about the current session
_user User Informaton
_process Process Meta Data
String

String.length(‘abc’)

String.Substring(‘abc’,5)

String.Contains(‘abc’,’c’)

String.pos(‘abc’,’c’)

String.replace(string1,search,replace)

String.compare(string1,string2)

Date

Date.now(format)

Date.DaysBetween(date1,date2)

Date.WorkingDaysBetween(date1,date2)

Date.hoursBetween(date1,date2)

Date.setTimezone(‘America/Los_Angeles’);
Date.now(“D M j — Y-m-d H:i:s T”);
Date.getDate();
Date.getDate()[‘hours’];

Date.getDate() Returns an array of date parts
Date.setTimezone(timezone) Defines the timezone for the script
Web

/* Web Service Example */

Web.addParameter(‘symbol’,’AAPL’);

Web.invokeService(‘http://www.webservicex.net/stockquote.asmx?WSDL’,’GetQuote’);

log(Web.result); /* just to help you understand the results */

Web.XMLtoArray(Web.result.GetQuoteResult);

Quote= Web.XMLtoArray(Web.result.GetQuoteResult);
Stock=Quote[‘Stock’];
log(“Stock: “~Stock[‘Symbol’] ~” last price “~Stock[‘Last’]);

Accessing Public Properties

Public properties on objects can be accessed by using the . syntax, similar to JavaScript:

Calling Methods

The . syntax can also be used to call methods on an object, similar to JavaScript:

Built-in Functions

The following functions are Omni-Script Extension:

Function description
return(expression) Returns the value of the expression and ends execution, useful for conditions.
log(expression) displays the value of the expression

Working with Functions

You can also use registered functions in the expression by using the same syntax as PHP and JavaScript. The ExpressionLanguage component comes with one function by default: constant(), which will return the value of the PHP constant:

 Working with Arrays

If you pass an array into an expression, use the [] syntax to access array keys, similar to JavaScript:

data["life"] + data["universe"] + data["everything"]

 

Supported Operators

The component comes with a lot of operators:

Arithmetic Operators

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • % (modulus)
  • ** (pow)

For example:

life + universe + everything

Bitwise Operators

  • & (and)
  • | (or)
  • ^ (xor)

Comparison Operators

  • == (equal)
  • === (identical)
  • != (not equal)
  • !== (not identical)
  • < (less than)
  • > (greater than)
  • <= (less than or equal to)
  • >= (greater than or equal to)
  • matches (regex match)

To test if a string does not match a regex, use the logical not operator in combination with the matches operator:

not ("foo" matches "/bar/")

You must use parenthesis because the unary operator not has precedence over the binary operator matches.

Examples:

life == everything

Logical Operators

  • not or !
  • and or &&
  • or or ||

For example:

life < universe or life < everything
  • ~ (concatenation)

For example:

firstName~" "~lastName

_case.items[1].processNodeId~'|'~_case.items[1].type~'|'~_case.items[1].label

Array Operators

  • in (contain)
  • not in (does not contain)

For example:

user.group in ["human_resources", "marketing"]

The $inGroup would evaluate to true.

Numeric Operators

  • .. (range)

For example:

user.age in 18..45',

This will evaluate to true, because user.age is in the range from 18 to 45.

Ternary Operators

  • foo ? 'yes' : 'no'
  • foo ?: 'no' (equal to foo ? foo : 'no')
  • foo ? 'yes' (equal to foo ? 'yes' : '')

Leave a Reply