Others
Studio Pro activities > Programming. Includes "Execute JS code" and "Execute Python".
Activities
Execute JS code | Execute Python |
---|---|
Run JavaScript code in Studio Pro | Run 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.
This is how the editor looks like.
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 is how the code looks like. As you can see, result variable is created outside of it using 'Assign value to variable' activity.
Also note that the script file is saved locally.
This is how we set the 'User notification' activity to display the output.
And here is the result of this operation.
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.
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:
- The Python path should be added to the Windows Environmental Variables.
- 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
- 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.
- Calculate a value: allows you to use a special formula or a special method to determine the path to the file.
- Save the previous step result: takes the result of the previous activity in the workflow as the file path.
Path to venv folder
- 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.
- Calculate a value: allows you to use a special formula or a special method to determine the path to the folder.
- 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.
- Set a value: allows you to manually specify parameters for launching the script.
- Calculate a value: allows you to use a special formula or a special method for determining the launch parameters.
- 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.
Updated about 1 year ago