Script Editor
Develop and test your Script in a secure and isolated environment.
Overview
Use Script Editor to develop and test your Scripts. Any Script can be used in any Process in your organization developed using programming languages that Script Editor supports.
Permissions Required
Scripts run securely and in isolation from within Docker containers called Script Executors. The Script Executor for each supported programming language contains the Software Development Kit (SDK) that supports extensibility to provide programmatic interaction with ProcessMaker Platform. When the ProcessMaker Platform instance calls a Script to run, the Script Executor for that programming language creates a Docker container corresponding with that programming language, runs the Script, and then destroys the Docker container. This ensures that any malicious script that anyone in your organization might inadvertently introduce to ProcessMaker Platform does not affect the instance or its hosting environment: Docker containers cannot access them. Furthermore, Docker containers cannot listen for inbound connections; therefore, a Docker container cannot be accessed externally.
Scripts are developed and tested in the same environment.
Access the Script Editor in the following ways:
Below is the Script Editor displaying a Script written in PHP.
![](https://docs.processmaker.com/~gitbook/image?url=https%3A%2F%2Fgblobscdn.gitbook.com%2Fassets%252F-LJ0aNaVW1m7sNsxVJLV%252F-Lt5KhCiBoVJXDez3lqh%252F-Lt5Lsgp_X4hBlF61puK%252FScripts%2520Editor%2520-%2520Processes.png%3Falt%3Dmedia%26token%3Df01491c9-c66c-481e-8c48-36a1ac65e1f9&width=768&dpr=4&quality=100&sign=af01458d&sv=1)
Script Editor Usage Guidelines
Follow these guidelines to develop and test Scripts in the Script Editor.
Develop Your Script
Develop the Script below the script's name and language description. Use the scroll panel to navigate your code not currently displayed. This is useful especially when you are editing a long Script.
Enter Mock Request Data Coming Into Your Script
Use the Sample Input panel to mock Request data that comes into your Script to test how the Script runs using Request data you expect.
Define the variables in a Screen when you configure its controls. See information about each control.
Follow these guidelines to mock Request data coming into your Script:
Open the Screen in which to view its JSON data model.
Enter Preview mode on the Screen page to view its JSON data model. Click the Preview button from Screen Builder's top menu to enter Preview mode.
Enter values into the control settings as if you were using the Screen in a Request. In the Data Preview panel, the JSON data model displays the key-value pairs in each object element. The keys' values are those you enter in the Screen preview. Understand what the key names are. Each key is derived from a Screen control's Variable Name setting value. Use these key names as variables in your Script. The Variable Name setting values become part of the Request data and contain the content that Request participants enter into that Screen during a Request. Mock these Variable Name setting values as input data to your Script.
After you have entered values into the Screen in Preview mode, the entire JSON data model displays in the Data Preview panel. Copy the JSON data model.
Paste the JSON data model into the Sample Input panel in Script Editor. If you use any variables as defined in the JSON data model in your Script, Script Editor uses those variable values during script testing.
Optionally, mock the Magic Variables that your Script would reference during an in-progress Request. ProcessMaker Platform uses a set of Magic Variables that become part of the JSON data model for all Requests. ProcessMaker Platform uses these Magic Variables to store user, Process, and Request related data for all Requests. During an in-progress Request, these Magic Variables are updated. All Magic Variables are preceded by an underscore (
_
) character in the JSON data model. Enter the Magic Variable into the Sample Input panel as part of the JSON data model, and then enter mock values for each. See Magic Variable Descriptions.Click Run.
In the Output panel, view the mocked Request data.
Enter Other JSON Data as Input to Your Script
Use the Configuration panel to include JSON configuration settings your Script uses when it runs. For example, include the Client ID and Client Secret values in JSON format for OAuth 2.0 verification to a third-party service's API your Script must access to access the API. By entering these values into the Configuration panel, you can verify during testing that these values are valid for the third-party service.
A Script may reference Screen control values during a Request by placing their Variable Name setting values within quotation marks ("
). In the example below, FullName
is the Variable Name setting value for a control to store a Request participant's full name:
Test Your Script
Click the Run button to test your Script. Script Editor evaluates any JSON data entered into the Configuration and Sample Input panels.
If the Script evaluates successfully, its output displays in the Output panel. If the Script does not evaluate successfully, the language engine evaluating the script displays an error.
Pass Request Data Into Your Script
Pass Request-related data into your Script in the following ways:
Request data: ProcessMaker Platform uses a schema-less JSON data model from which to read, write, and store Request data. Since the JSON data model is schema-less, meaning that it does not require a specific schema or structure from which ProcessMaker Platform assets must conform, the JSON data model is structured from the JSON objects in assets used in a Request, such as the Variable Name setting values in a Screen or variables a Script creates. When an in-progress Request routes through the Process, Request data aggregates into the JSON data model, thereby becoming Request data. Users or group members that have the Requests: Edit Request Data permission may view the JSON data model for a completed Request. This JSON data model displays from the Data tab in a completed Request's summary. Below is an example. Scripts can call Request data by referencing these JSON objects derived from Variable Name setting values in Screens.
Script Task element Configuration: Enter JSON data to pass to the Script when configuring the Script task element in Process Modeler. In the example below, the data from JSON Variable
Email
is being passed to the Script using the Script Configuration panel of a Script Task element.Magic Variables: ProcessMaker Platform uses a set of Magic Variables that become part of the JSON data model for all Requests. ProcessMaker Platform uses these Magic Variables to store user, Process, and Request related data for all Requests. During an in-progress Request, these Magic Variables are updated. All Magic Variables are preceded by an underscore (
_
) character in the JSON data model. See Reference Magic Variables in ProcessMaker Platform Assets.Environment Variables: The sensitive information that an Environment Variable represents can pass to a Script when it runs. Usage depends on the programming language that the Script uses. In the usage examples below,
ENV_VAR_NAME
represents the name of the Environment Variable. See Variable Syntax, Usage, and Examples.
ProcessMaker Platform and Environment Variable Syntax, Usage, SDK, and Examples
ProcessMaker Platform uses two global variables that Scripts can call. Variable usage depends on the programming language that the Script uses. Below is a description of these global variables:
Data: The
data
variable is a JSON object that contains all Request data to the moment a Script runs.Config: The
config
variable is a JSON object that contains any special configuration to be passed to the Script prior to it running. In Script Task elements of a Process model, special configurations are entered into the Script Configuration setting. See Reference a Request Variable from a Script Configuration Setting as to the best practice when configuring Scripts from Script Task elements in a Process model.
Every Script Executor from which a Script runs has the following default Environment Variables from which a Script may get its value. Refer to the tabs below how to get these Environment Variable values for each supported programming language. Below is a description of these default Environment Variables.
ProcessMaker Environment Variable | Description |
HOST_URL | Domain for the ProcessMaker Platform instance. |
API_HOST | ProcessMaker Platform instance API to which to make all RESTful API calls. |
API_TOKEN | Token a Script uses to authenticate to our API host. Note that this API token is only valid for the lifetime of the Script: after the Script runs and the Script Executor's Docker container from which that Script ran, its API token is no longer valid. |
Refer to the tabs below how to use variables in supported programming languages.
Below is a sample Script that uses PHP. Refer to the comments denoted with //
that describe how the sample functions:
How to get an Environment Variable.
How to get a value from the configuration object.
How to get a value from a data object.
Call the Software Development Kit (SDK).
Retrieve All Tasks for a User
The following sample PHP script provides an example to get all Tasks currently assigned to a user. This example also demonstrates the use of optional arguments such as the Request ID or a Task filter.
Get a Task using the Task ID
The following sample PHP script provides an example to retrieve a single Task using its Task ID.
Complete a Task
The following sample PHP script provides an example of completing a Task when the Task ID is known.
Save Your Script
A Script can be saved in two ways depending if the Versioning package is installed. See the following sections regarding how a Script may be saved:
Versioning package is not installed: Save a single version of your Script.
Versioning package is installed: Save multiple versions of your Script.
Save a Single Version of a Script
Save Multiple Versions of a Script
Permissions Required
Permissions are required to do this.
Package Required
The Versioning package must be installed to save multiple versions of a Script.
When the Versioning package is installed, multiple versions of a Script can be saved. A version is a set of changes made to a Script at a particular time by a Process designer. Versioning maintains a record of all named and unnamed changes to that Script. Any of these versions may be viewed or retrieved, if needed. See the Versioning package for more information.
Follow these guidelines to save a new version of your Script:
Do one of the following:
Save an unnamed version:
Follow these steps to save an unnamed version:
Click Save to save an unnamed version. Otherwise, click Cancel to return to Script Editor without saving this version. As a best practice, save unnamed versions only to save work that is in active development and do not need a "milestone" set for this Script. Otherwise, Process designers that manage versions of this Script do not view unnamed versions when the Only show named versions toggle key is enabled while viewing that Script's version history.
Save a named version:
Follow these steps to save a named version:
In the Version Name setting, enter a name for this version. The version name displays when viewing the version history of that Script and helps identify this version. Although this setting is not required, as a best practice name each version for easier maintenance, documentation, and auditing purposes. Name the version that describes the "milestone" set for this Script.
In the Additional Details (optional) setting, optionally enter details of the changes made in this version. The additional details display when viewing the version history of that Script and helps other Process designers or Administrators understand the changes made in that version. Enter details which concisely summarize the changes made in this version.
Click Save to save this version. Otherwise, click Cancel to return to Script Editor without saving this version.
Related Topics
What is a Script?What is a Screen?Manage Script CategoriesWhat is a Script Executor?Reference Magic Variables in ProcessMaker Platform AssetsView ScriptsCreate a New ScriptSearch for a ScriptConfigure a ScriptEdit a ScriptCopy a ScriptDelete a ScriptC# PackageJava PackageR PackagePython PackageVersioning PackageWhat is a Package?Last updated