Server-Side Javascript ES6 API Reference
Introducing a new Javascript ES6-based backend engine designed to elevate the functionality and capabilities of our application. In terms of custom RMP function this engine is feature-equivalent to the older Freemarker engine. However, developers can use the more powerful Javascript language compared to the more limited scope of Freemarker.
This section will walk you through the essential steps and concepts, and help you streamline your workflow, whether you're looking to automate tasks, extend functionality, or solve complex problems.
Please note that RMP always offered Javascript as a backend language (without custom RMP functions) based on Mozilla Rhino. However, this older JS engine is now considered deprecated.
Limitations
- Scripts executed JS ES6 are executed in a resource-isolated environment which is more strict in terms of time and memory limits
- While there are slight differences between the older engine ("Mozilla Rhino") and ES6, you should be able to migrate scripts with little effort. The most significant difference is the way data is return back into the process engine - see RMPData.setOutput(...) below.
- Initially access to the new JS engine will be comparatively rare. This may result in a slight delay (ca. 5 seconds) when executing a script. After the first call the new engine is “warm” for a while and will respond instantly.
- Multi-account users (e.g. third-party support users) are not supported
Basic Script Setup
The new engine can be triggered when specifying a script like this (e.g. as input/output parameters of a process):
<@script env="js">
... javascript code here ...
</@script>
Please note that compared to the existing engine, you have to specify <@script env="js"> for Javascript ES6 rather than <@script env="javascript"> used by the old Mozilla Rhino Javascript engine.
Besides the standard Javascript language, there are a number of RMP Objects which provide access to custom functions. e.g. for creating a custom MongoDB collection, you'd choose the RMPCollection class with the corresponding function name like:
<@script env="js">
var someResponse = RMPCollection.createCollection("some collection name", false, false);
</@script>
Broadly, these custom functions resemble those from the Freemarker environment.
Response Handling
There are 2 ways for returning data to the caller (e.g. a process).
The response object has to be an Object that can be translated into a String. Namely:
- String
- Number
- Boolean
- Map (JSON Object)
- Array (JSON Array)
Option 1:
You can specify the response explicitly via the custom function below. All output objects will be transformed into text format.
<@script env="js">
RMPData.setOutput(someResponseObject);
</@script>
Option 2:
You can implement a function that returns the value.
<@script env="js">
(function(t) { return someResponseObject; })
</@script>
Error Handling
The functions will produce an exception with a reasonable error message, and the execution fails.
Saving Data into the Process Context
<@script env="js">
...
RMPData.setContextVariable(someKey, someValue);
...
</@script>
JS ES6 vs Freemarker
Freemarker:
<#assign result = append_file("73f01850-1a85-11ec-8413-8c859067f180","coucou")>
${result}
So you use the <#assign x=y> for assigning a value to a variable.
${x} is used to return the variable value to the workflow / app.
You may also spot the following variation:
<#assign result>
append_file("73f01850-1a85-11ec-8413-8c859067f180","coucou")
</#assign>
${result}
JS ES6 (see also Response Handling):
<@script env="js">
var result = RMPFile.append("73f01850-1a85-11ec-8413-8c859067f180","coucou");
RMPData.setOutput(result);
</@script>
var x = y; is a standard JS value assignment.
User RMPData.setOutput(x); for returning the variable value to the workflow / app.
Javascript Reference Guide (External - by Mozilla Foundation)
RunMyProcess-specific Custom Functions for Workwflows
Please refer to the following pages for the function documentation:
- Create Collection
- Rename Collection
- Drop Collection
- Create Index
- Delete Index
- List Index
- Aggregate
- Count Documents
- Find
- Insert Object
- Insert Objects
- Update Objects
- Delete Objects
- Delete Field
- Update Field (updateMany)
- Update Field (updateOne)
- Import CSV
- Import JSON
- Get Current User
- Get Execution Mode
- Get All Context Variables
- Get App Instance ID
- Get Context Variable
- Get Project ID
- Log (message)
- Log with (String, String)
- Set Output
- Set Context Variable
- Append File
- Create File
- Delete File
- Get File Content
- Save File Content
- Get File Description
- Save File Description
- File Replace
- File Size
- Index Of
- Last Index Of
- Read Excel Spreadsheet
- Unzip
- Zip
- Get Project Vault
- Save Project Vault
- Delete Project Vault
- Get Access URL
- Get Project Metadata
- Save Project Metadata
- Get Custom List
- Save Custom List
- Get OAuth2 Token
- Add User to Lane
- Remove User from Lane
- get Next URL
- Get Request Info
- Set Request Status
- Get Task URL
- Inject Parameters
- Set Lock
- Remove Lock
- Raise Error
- Read File Add Lane with (fileIds, laneIds)
- Read File Add Lane with (fileIds)
- Read File Add User with (fileIds, userIds)
- Read File Add User with (fileIds)
- Read File Remove Lane with (fileIds, laneIds)
- Read File Remove User with(fileIds, userIds)
- Read File Remove User with (fileIds)
- Read File Remove Lane with (fileIds)
- Update File Add Lane with (fileIds)
- Update File Add Lane with (laneIds)
- Update File Add User with (fileIds, laneIds)
- Update File Add User with (fileIds)
- Update File Remove Lane with (fileIds, laneIds)
- Update File Remove Lane with (fileIds)
- Update File Remove User with (fileIds, userIds)
- Update File Remove User with (fileIds)
- Get Applications
- Get Lanes
- Get Lane Users
- Get User Lanes
- Get Manager
- Get User Data
- Has Right in Lane
- Impersonate
- Get User Metadata
- Save User Metadata
- Get User Preferences
- Save User Preferences
Please give details of the problem