Admin Manual / Appendix A – Witly Script / Syntax
Syntax

See the below table for the syntax of Witly script.

${control(formatter:function(variable | field [operator]   [literal value | expression value])) …}


Element

Description

${ }

The script container. Witly will only evaluate formula expression inside container.

Field

Refer to the value of field. The syntax for a field reference is Object.FieldName. For example, Object.Amount will represent field amount of the current module.

Operator

A symbol that specifies the type of calculation. Witly supports the following types of operators:

  • +: add
  • -:  subtract
  • *:  multiply
  • /:  divide

For example, ${Object.Amount * 10}. This expression will multiply the amount with 10.

Literal value

A number you enter that will be used exactly as it is. For example, if you want to calculate discount price by 10%, your formula should be: ${Object.Amount * 0.1}

Expression Value

A value in a form of expression that will change when being evaluated. You can use these types of expressions:

  • y: year 
  • m: month
  • d: day
  • h: hour
  • n: minute
  • s: second
  • wd: working day (exclude holiday)

For example, you can use expression like ${Date.Now-1d} and ${Date.Now+1y} to get the date value of yesterday and next year, respectively.

Function

Aggregate function that requires input from fields and returns a value. Witly supports the following types of functions:

  • Sum: Returns the total sum of a set of records.
  • Avg: Returns the average value of a set of records.
  • Min: Returns the minimum value in a set of records.
  • Max: Returns the maximum value in a set of records.
  • Count: Returns the number of records.
  • First: Returns the first value of a set of records.
  • Last: Returns the last value of a set of records.

For example, if you want to calculate the total amount of selling products. Your formula should be: ${Sum(Object.Product[\"Amount\"])}

Formatter

A pattern that formats the value. Only date and numeric field type are supported by the formatter. See the syntax below.

  • Zero Prefix Formatter: Inserts leading zero to the left of the remaining N digits. For example, ${0000:Object.Amount} will add leading zero to the value of the remaining digits. For example, If the field values are 100 and 1000, the result will be 0100 and 1000, respectively.
  • Date Formatter: Format date with d (day), M (minute), y (year), h (hour), m (month), s (second), wd (working day) formatter. For example, ${ddmmyy:Object.Now} will return the current date in 061017 format. The length of formatter will represent the number of digits. 

Control

A command to control flow of the script. The support command is:

  • For: Iterate through the numerical values. The syntax is
    ${For i= Count} … ${EndFor}.
    The count can be used with literal value or field value. For example,
    ${For i=Object.Product.Count}
    ${Object. Product[i].Name}
    ${EndFor}
    The script will loop N times and return a list of product names.
Last modified on Jan 23, 2018