Others

Studio Pro activities > Programming. Includes "Execute JS code" and "Execute Python".

Activities

Execute JS codeExecute Python
Run JavaScript code in Studio ProRun Python code in Studio Pro

Execute JS code

Description

This activity is used to run JavaScript code. It can be used for a wide variety of tasks such as maths operations, data processing, and others.

You can use the following libraries with this activity: 'lodash', 'moment', 'mustache'.

A few notes about variables usage: the variables initialized within the Execute JS code activity are local which means they can not be accessed outside. However, the variables created using the 'Assign value to variable' activity are global and can be used and modified in the Execute JS code activity.

We also have support for these JavaScript libraries: lodash, momentjs, mustache. In order to call them, you need to use the reserved commands:

let newArr = _.cloneDeep(arr), //making a deep clone of an array through lodash
let today = moment(), //getting the current date through momentjs
let output = mustache.render("{{title}} spends {{calc}}", view) //using mustache

🚧

Note

We do not support operations with DOM-elements, browser APIs, or js libraries such as fs and similar. Arrow functions, classic functions, classes, and libraries such as Math are supported.

Editing code

The code is the main parameter of this activity. You can create and edite it in a separate built-in editor and store it in a .js file. This file is placed in the same folder where the .neek file is stored. If you delete this file, the data is lost.

To edit code, click the Edit Code button to open the editor.

Edit Code button

Edit Code button

This is how the editor looks like.

Code editor in a new Studio Pro tab

Code editor in a new Studio Pro tab

You may also use other popular code editors to edit the code.

Note that you can see the list of used variables in the respective tab:

Example

Let us provide an example of how this activity can be used. We have this workflow that performs some calculations with two numbers, then saves the result in a variable and displays it in a notification window.

This workflow executes a JavaScript file

This workflow executes a JavaScript file

This is how the code looks like. As you can see, result variable is created outside of it using 'Assign value to variable' activity.

The code used in this example

The code used in this example

Also note that the script file is saved locally.

Script file name and path

Script file name and path

This is how we set the 'User notification' activity to display the output.

This displays a text message and the result variable value

This displays a text message and the result variable value

And here is the result of this operation.

Result variable value is displayed

Result variable value is displayed

Timeout

Optionally, you can use this parameter to set a time limit (in seconds) for the execution of the activity.

If any activity takes longer than the time you set to be executed, you can see a warning message on the console. After the timeout, you are able to stop the workflow by hitting the Ctrl+]command.

⬅️

Back to the top


Execute Python

Description

This action allows you to run scripts written in Python in your workflow. Python 3 has to be installed on the computer.

Requirements

There are two requirements to make this activity work correctly:

  1. The Python path should be added to the Windows Environmental Variables.
  2. The user should create a venvand set it as a parameter.

πŸ“˜

Note

For more information on these actions see the related Phyton documents: Using Phyton on Windows and Creating Virtual Environments.

Parameters

Path to .py

  1. Set a value: allows you to specify the path to the .py script file manually. Click the "Select" button to open File Explorer and select the file path.
  2. Calculate a value: allows you to use a special formula or a special method to determine the path to the file.
  3. Save the previous step result: takes the result of the previous activity in the workflow as the file path.

Path to venv folder

  1. Set a value: allows you to manually specify the path to the virtual environment folder (venv). Click the "Select" button to open File Explorer and select the path to the folder.
  2. Calculate a value: allows you to use a special formula or a special method to determine the path to the folder.
  3. Save the previous step result: takes the result of previous activity in the workflow as a folder path.

Parameters

Here you can specify parameters for running the script.

  1. Set a value: allows you to manually specify parameters for launching the script.
  2. Calculate a value: allows you to use a special formula or a special method for determining the launch parameters.
  3. Save the previous step result: takes the result of the previous action in the workflow as launch parameters.

Comment

Contains an annotation to the activity. The input text will be displayed above the activity name.

How to use it?

You can pass and return data from Studio Pro when working with Python, see this article for more details.

⬅️

Back to the top