Skip to content

Javascript Code

Execute a Javascript code snippet on the active page.

Timeout

The maximum time the node will run, with a default timeout of 20 seconds. If the code execution completes within the timeout, the workflow will proceed to the next nodes. If the node does not complete within the timeout, the workflow will stop.

Execution Context

The execution context will always be the active tab.

Run in iframe

If you want to execute the code in the node within an iframe, specify the iframe’s selector or link here.

For example, if there is an iframe window, you can use its link, which is the value in the src attribute of the iframe tag, or a selector like iframe.payment-verification as shown below:

AttributesAttributes

JavaScript code

You can use Javascript code to run here.

There are some built-in functions that you can use within the node.

omniloginRefData(keyword, path)

This function retrieves data from outside the workflow to use in the JavaScript code node. You can use data from a column in:

  • Table First, insert a text hello into the words column in the table, where the words column is the first column with data.

Attributes

Then, in the JavaScript code node, use the following formula to retrieve the first element in the table and get the value of the words column.

Attributes

The firstRow variable in the node will then receive the value hello.

Attributes

  • Global Data First, create an array of data in Global Data as follows:

Attributes

Then, in the JavaScript code node, use the following formula to retrieve the value from Global Data and assign it to the data variable.

Attributes

The data variable in the node will then receive the array value.

Attributes

  • Data in the Loop Data Node First, input data into the Loop Data node from the Spreadsheet node with the following data:

Attributes

Then, pass it through the Loop Data node from the Spreadsheet node.

Attributes

Next, in the JavaScript code node, use the following formula to retrieve the value from the Loop Data node and assign it to the data variable.

Attributes

The formula below is slightly different because the structure in the Loop Data node includes an additional data key wrapping the value of each iteration, so you need to access it through that key. The formula must be wrapped in the JSON.stringify function because the retrieved data is not in JSON format and must be converted to JSON to be displayed by the alert function. However, if you want to use the data variable as an object within this node, you don’t need to include that formula.

The data variable will then receive the value of one iteration from the Loop Data node.

Attributes

  • Variable First, insert a text nam into the name variable.

Attributes

Then, in the JavaScript code node, use the following formula to assign data from the name variable outside the workflow into the JavaScript code node.

Attributes

The data variable will then have the following value:

Attributes

  • Spreadsheet (Excel) Node First, input a file into the Spreadsheet node with the following values:

Attributes

Then, in the JavaScript code node, use the following formula to assign data from the formula retrieving data from the Spreadsheet node to the data variable in the JavaScript code node.

Attributes

The data variable will then have the following value:

Attributes

  • Google Sheets Node First, input a file into the Google Sheets node with the following values:

Attributes

Then, in the JavaScript code node, use the following formula to assign data from the formula retrieving data from the Google Sheets node to the data variable in the JavaScript code node.

Attributes

The data variable will then have the following value:

Attributes

Example

Here, I will take an example of retrieving external values into the JavaScript code node for checking.

First, input data into the Loop Data node from the Spreadsheet node with the following data:

Attributes

Then, pass it through the Loop Data node from the Spreadsheet node.

Attributes

Next, in the JavaScript code node, use the following formula to retrieve the value from the Loop Data node and assign it to the data variable. The formula below is slightly different because the structure in the Loop Data node includes an additional data key wrapping the value of each iteration, so you need to access it through that key. Then, use the checkName function to check if the value of the name key in the data variable is hai or manh. The function will return true if the value exists and false if no value is found.

Attributes

When running the node, I will see the value true displayed, meaning this iteration contains the value hai or manh.

Attributes

omniloginSetVariable(name, value)

Assign the value of a variable in the node to another variable to use it outside this node.

Example

For example, if I want to create a random value between 1 and 100 in the JavaScript code node using the following code: const randomNumber = Math.floor(Math.random() * 100) + 1;

Then, to use this value in the workflow outside this node, I use the omniloginSetVariable function to assign the value of the randomNumber variable to a value variable for use outside this node with the formula omniloginSetVariable('value', randomNumber).

Attributes

When running this node, I will see a value variable created and assigned the value as shown below, and I can then use that variable in the workflow with the formula to retrieve the value of a variable.

Attributes

Execute on All New Tabs

This will execute the Javascript code whenever Automation creates a new tab or switches to a tab. When this option is enabled, the Javascript code node no longer requires an active tab to function, and built-in functions like omniloginRefData, omniloginNextBlock, etc., will not be available.

Preload Code File

Load a Javascript code file before executing this node.

  • URL: The path to the Javascript code file.