Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

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:

  • response: The raw text response from the previous action.

  • jsonResponse(): Converts the 'response' into a JSON object.

  • context: Basic details of the action like its name, URL, method, headers, payload or any full scope variable, etc. Use dot notation to access the variable.

  • path(anyObject, jsonpath): Fetches specific parts of a JSON object.

  • getIssue(): Retrieves the issue in JSON format. If there's no issue, it returns null.

  • domParser: an implementation of https://www.npmjs.com/package/xmldom

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

  • No labels