Skip to main content
Version: Classic

JavaScript


The JavaScript API is used for mappings and for conditional subtemplates. The Document Parameter and scripting do not use this definition yet. ES5 JavaScript is supported.


Expressions​

Expressions in conditions can be defined in two formats:

Expression

An expression can be specified directly, e.g. "OO('forname') + ' ' + OO('lastname')".

Main function

If a function main() exists, it is called and the return value is evaluated. This way, more complex issues can be represented, such as adapting a Swiss phone number to the international format. This would be achieved by means of a regular expression (regex) in JavaScript as follows:

function main()
{
// normalizes all phone numbers
// 0715110500 => +41 71 511 05 00
// +41 71 511 05 00 => +41 71 511 05 00
var input = OO('phonenumber').replace(/ /g, '');
var patt = /((\+|00)41|0)([0-9]+)/;
var matchArray = patt.exec(input);
var number = matchArray[3];
return "+41 " + number.substring(0,2) + " " + number.substring(2,5)
+ " " + number.substring(5,7)+ " " + number.substring(7,9);
}

OO API object​

An API object is available as OO in each case. Thereby OO(identifier) can be used as short form for OO.getValue(identifier). If an unknown key is passed, undefined is returned.

  • Mappings OO returns the source values. For example, OO('phone') in the interface configuration returns the value in the phone column.
  • Subtemplates OO each returns the values in the OneOffixx Custom XML Part, so for example OO('DocParam.Subject).