Scripted Variables

Using Scripted Variables in JavaScript:

Scripted Variables let you run scripts to create custom variables for your web actions. These variables can be used anywhere in your setup, like in URLs or post bodies, with the Mustache format {{ variable-name }}.

How to Create a JavaScript Variable:

  1. Navigate to the Variables tab.

  2. Switch to 'Javascript Variables'.

  3. Click "Add".

  4. Name your variable in the "MyVar" field.

  5. Enter your JavaScript code in the "Script" field.

Important Points about the Script:

  • The script should always return a value.

  • This returned value is what gets saved as the variable. You can use it in your setup with Mustache syntax. Example: {{ MyVar }}

Built-in Variables and Functions for Your Script:

const xmlDoc = domParser.parseFromString(response.data, 'text/xml'); const resultNode = xmlDoc.getElementsByTagNameNS('xmlns attribute', 'element name ')[index of the elements];

Example:

The action is a child action to another action. Let's say the child receives the following input data:

{ “name”: “Donald Duck”, “email”: “donald@cartoonducks.com” }

To create a scripted variable that transform the name property to lowercase, the code would be:

return jsonContext.payload.name.toLowerCase();