Javascript Code

The Action option in the JavaScript Code block allows you to run JavaScript commands within GemPhoneFarm. This can be used for tasks such as setting up complex conditions or executing necessary commands.


Execution Context Option

You can choose to run the JavaScript code by selecting the type of Execution Context.

Active Tab: Runs on the currently active web page.

Background: Runs JavaScript in the background of the application.


Wait Time

The maximum time the node will run. By default, it is set to 20 seconds. If the code completes within the specified time, the process will proceed to the next node. If the node does not complete within the specified time, the process will stop.


Functions Inside the JavaScript Code Block

The JavaScript Code block contains pre-built functions that you can call within this node. These functions include:

NextBlock()

Select the Next Block to Run and Store Data in a Table Column

You can choose which block to run next and store data in a table column.

Parameter Syntax:

NextBlock({ name: 'A', age: 24 });
// Or
NextBlock([{ name: 'A', age: 24 }, { name: 'A1', age: 24}])
// Proceed to the specified Node
NextBlock({ name: 'A' }, { nextBlockId: '4dxcxa3' })

Example:

NextBlock({Data: 'A'}) // This stores 'A' in the Data variable in the table.

It is necessary to create the column in the table beforehand.

Functions that Can Be Used with NextBlock()

Insert

This Defines Whether We Want to Insert Data or Not

The value used will be boolean, such as true/false. If you don't specify insert, the default value will be true.

Example Usage:

NextBlock({Data: 'A'}, {insert: true})
NextBlock({Data:’A’},{insert:false})

The Result: A will not be stored in the Data variable because insert is set to false.

In this example, the Insert Data block has already set B in the Data variable beforehand.

nextBlockId

This Function Specifies What Should Run Next

It allows you to specify what should run next by providing the ID of the block. For example, if two blocks are connected to a JavaScript code, you can define which one should execute next.

Example:

NextBlock({Data:’A’},{nextBlockId:’vwbv3nv’})

You Can Copy the ID by Hovering the Mouse Over the Block

If we don't specify which block should run next, the blocks will execute simultaneously.

However, if the nextBlockId is specified, you can choose which block will execute next.

replaceTable

Replace the Variable Value in the Table with the Value Set in the First Parameter

You can specify whether to replace the value or not using a boolean value (true/false). The default value is false.

NextBlock({Data: "A"}, {nextBlockId: 'vwbv3nv', replaceTable: true})

When the replaceTable parameter is set to true, the value in the Data variable will be replaced with the new value.

RefData(keyword, path?)

Used to Retrieve Data from Variables or Tables

This is used to retrieve data from a variable or table in the program. For example:

If there is a variable named number in variables, you can use RefData('variables', 'number') to retrieve that variable's data.

SetVariable(name, value)

Used to Declare or Update Variables or Tables

This is used to declare or update data in a variable or table in the program. For example: You can declare a new variable using SetVariable('name', 'Bob') to create a variable named name with the value Bob

If a Variable Already Exists, It Can Be Updated

For example, if there is an existing variable number with the value 10, you can use SetVariable('number', 20) to change its value to 20.

Last updated