Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 }}).

Creata a Javascript variable

...

How to Create a JavaScript Variable:

  1. Navigate to the Variables tab.

  2. Toggle Switch to 'Javascript variablesVariables'.

  3. Click the "Add" button.

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

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

Important Points about the Script

...

:

  • The script

...

  • should always return a value

...

  • .

  • This returned value is

...

The script has the following context already provided as variables to use;

...

response

...

the response of the parent action in raw text

...

jsonResponse()

...

a function that turns the response into json object

...

context

...

raw context of the action, such as name, url, method, headers

...

jsonContext()

...

a function that turns the context into json object.
example getContext().url gives the url

...

path(anyObject, jsonpath)

...

a function that returns the value in the object specified by the path.
Used when there is a need to pick a part of a json object.

...

getIssue()

...

  • what gets saved as the variable. You can use it in your setup with Mustache syntax.

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, etc.

  • jsonContext(): Converts 'context' into a JSON object. For example, getContext().url retrieves the action's URL.

  • 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.