You can choose from several step types that allow you to write your own custom Javascript. The function signature for all JS-related step types looks like:
/**
* @param trigger The trigger that started this execution
* @param steps The list of steps that have been executed up until this point for this execution and all of their step execution values
* @param info Metadata about this formula
* @param config The configuration values set on the formula instance (config variables)
* @param done The callback function that you will need to call at the end of your script step
*/
function (trigger, steps, info, config, done) {
// your Javascript will be executed here
}Note the following when writing javascript in formulas:
- For all scripts, Javascript
strictmode is enforced. - You can use
console.logto log data to the Javascript console to help debug your formula. - You can use
notify.emailto send an email notification. - ES6 is supported.
- The function parameters are immutable, meaning they cannot be assigned to directly. To change an object or value passed into the function, first copy it to your own local variable and then make the necessary changes.
Functions
console.log(str): Log something from the script. This logged value is returned in an array calledconsole, which will be available to see as a step execution value. Takes astringas a parameter. Unlike the standard Nodeconsole.log(str), this version only accepts a single parameter.notify.email(to, subject, body): Send an email notification directly from a Javascript step.tocan be a single email or a comma separated list of emails,subjectis the subject of the email andbodyis the body of the email. A value will be returned in an array callednotify, which will be available to see as a step execution value. Takes threestringparameters. You can reference anything from the context when passing into,subjectorbodyin the same way you can access these variables elsewhere in the Javascript. For example:notify.email(steps.previous-step.email, steps.previous-step.subject, steps.previous-step.emailPrefix + '<br>This is the main body.');