Skip to main content
Version: 0.43

Utils

The application.utils object gives your form scripts a way to build strings from a template and some data, without writing your own string-replacement logic. It currently exposes a single function, evaluateString.


application.utils.evaluateString

Evaluates a template string written in Mustache syntax against a data object, replacing each {{ }} placeholder with the matching value from that object.

application.utils.evaluateString(template: string, data: any): string

Form type to use: Any form type - application is available everywhere standard script variables are.

Example - Build a summary line from record data:

const data = {
id: 'REC-1001',
name: 'Shesha',
status: 'Active',
};

const template = 'Record {{id}} belongs to {{name}} and is currently {{status}}.';

const result = application.utils.evaluateString(template, data);

console.log(result);

// result: "Record REC-1001 belongs to Shesha and is currently Active."
Formatting dates

The data object passed in automatically gets a dateFormat helper you can wrap around a date value, so you don't have to format it yourself first:

const template = 'Created on {{#dateFormat}}{{createdDate}}{{/dateFormat}}.';