×

Please give details of the problem

Skip to content

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)

  • Javascript Reference
  • RunMyProcess-specific Custom Functions for Workwflows

    Please refer to the following pages for the function documentation:

  • Application Management
  • Collection Management
  • Scope Management
  • File Management
  • Project Management
  • Request Management
  • User Management
  • Utilities