See the supported connectors for Application Integration.

JavaScript task

The JavaScript task lets you write custom JavaScript code snippets for your integration.

Using the JavaScript Editor, you can code complex data mapping logic for your integration, perform variable assignments, and add or modify integration variables.

The JavaScript Editor supports the following features:

  • A minimap that displays a high-level overview of the script code and helps with quick navigation.
  • Syntax/code highlighting, indentation, and line numbering for easier code readability and structure recognition.
  • Error highlighting to find and track errors in code.
  • Folding to expand and collapse regions of the script code.
  • Click-to-copy option to copy the script code to the clipboard.

Configure the JavaScript task

To add a JavaScript task to your integration, perform the following steps:

  1. In the Google Cloud console, go to the Application Integration page.

    Go to Application Integration

  2. In the navigation menu, click Integrations.

    The Integrations page appears listing all the integrations available in the Google Cloud project.

  3. Select an existing integration or click Create integration to create a new one.

    If you are creating a new integration:

    1. Enter a name and description in the Create Integration pane.
    2. Select a region for the integration.
    3. Select a service account for the integration. You can change or update the service account details of an integration any time from the Integration summary pane in the integration toolbar.
    4. Click Create.

    This opens the integration in the integration editor.

  4. In the integration editor navigation bar, click Tasks to view the list of available tasks and connectors.
  5. Click and place the JavaScript element in the integration editor.
  6. Click the JavaScript element on the designer to view the JavaScript task configuration pane.
  7. Click Open script editor to view and edit the JavaScript Editor.
  8. Write your JavaScript code inside the executesScript(event) function that is automatically created in the JavaScript Editor. Close the editor once complete, any changes will be autosaved.

    For information about accessing integration variables and the supported functions, see Using the JavaScript Editor.

    For information about viewing the generated execution logs, see Execution logs.

The following image shows a sample layout of the JavaScript Editor: image showing javascript editor image showing javascript editor

Use the JavaScript Editor

To view and edit the JavaScript Editor, go to the JavaScript task configuration pane and click Open script editor. The JavaScript Editor by default contains a function named executesScript(event), where:

  • executesScript(): the function that is called when Application Integration executes the JavaScript task during an integration's run.
  • event: the in-memory object of Application Integration.

    For information about the supported methods of the event object, see Access integration variables.

JavaScript execution engine

Application Integration uses the JavaScript execution engine that is based on Rhino 1.7.14, which doesn't support all ES6 syntax–for example, variable declaration with let is not supported. Only the ES5 syntax autocompletion is supported. To view all of the supported ES6 syntax, see Rhino ES2015 Support.

Access integration variables

Variables defined in your integration can be accessed from the JavaScript Editor using the Application Integration in-memory event object.

The following methods are supported to access integration variables from your JavaScript Editor:

Function name Description Usage

getEventExecutionInfoId

Returns the integration's run execution ID.

Return type: String

Syntax: event.getEventExecutionInfoId()

Example:

function executeScript(event) {
  event.getEventExecutionInfoId();
  }
      

getGoogleCloudProjectId

Returns the Google Cloud project ID.

Return type: String

Syntax: event.getGoogleCloudProjectId()

Example:

function executeScript(event) {
  event.getGcpProjectId();
  }

getIntegrationName

Returns the current name of the integration.

Return type: String

Syntax: event.getIntegrationName

Example:

function executeScript(event) {
  event.getIntegrationName();
  }

getParameter

Returns the value of the provided integration variable.

Return type: Data type of the integration variable

Syntax: event.getParameter("variable_name")

Input parameter: Integration variable name. If the variable_name is an auto-generated variable, then enclose the variable in backticks (``). For example, `responseBody`.

Example:

function executeScript(event) { 
  event.getParameter("var1");
  }

getRegion

Returns the name of the integration region.

Return type: String

Syntax: event.getRegion()

Example:

function executeScript(event) {
  event.getRegion();
  }

log

Writes the specified value to the execution logs.

For information about viewing the generated execution logs, see Execution logs.

Syntax: event.log(value)

Input parameter: Any variable or function that is used in the script.

Example 1:

function executeScript(event) {
  event.log(event.getParameter("var1"));
  }

Example 2:

function executeScript(event) {
  event.log("Lorem ipsum");
  }

setParameter

Sets or updates the value of an integration variable.

Syntax: event.setParameter("variable_name", "variable_value")

Input parameter: This function takes the following arguments:

  • First argument: Variable name. If the variable_name is an auto-generated variable, then enclose the variable in backticks (``). For example, `responseBody`.
  • Second argument: Value.

Example:

function executeScript(event) {
  event.setParameter("`responseBody`", "NewStringValue");
  }

Set task parameters

If your integration has multiple large sized parameters that are not used by the JavaScript task, you can set the TaskParameter field for the JavaScript task to improve performance.

To set the TaskParameter field for the JavaScript task, select one of the following options:

Console

  1. Go to the Application Integration page.

    Go to Application Integration

  2. Select an integration. The integration editor opens.
  3. Click Action > Download Integration > Integration Version. The integration version is downloaded as a JSON file.
  4. Open the integration version file in an editor, and then do the following:
    1. Locate the taskConfigs field with the task as JavaScriptTask. In the parameters field, locate the parameter named script.
      "taskConfigs": [{
        "task": "JavaScriptTask",
        "taskId": 1,
        "parameters": {
          "script": {
            "key": "script",
            "value": {
              "stringValue": "function that is called during the JavaScriptTask execution"
            }
        }"
      }]
      
    2. In this parameters field, add parameters that are used in the JavaScriptTask field by using the following template:
      "ParamName": {
        "key": "ParamName",
        "value": {
          "stringValue": "$ParamName$"
        }
      }
      
  5. Save the changes that you made to the integration version file.
  6. Upload the integration version file to the integration.

API

  1. To download the integration version, make a call to the projects.locations.integrations.versions.download method with the filFormat set to JSON.
  2. Open the integration version file in an editor, and then do the following:
    1. Locate the taskConfigs field with the task as JavaScriptTask. In the parameters field, locate the parameter named script.
      "taskConfigs": [{
        "task": "JavaScriptTask",
        "taskId": 1,
        "parameters": {
          "script": {
            "key": "script",
            "value": {
              "stringValue": "function that is called during the JavaScriptTask execution"
            }
        }"
      }]
      
    2. In this parameters field, add parameters that are used in the JavaScriptTask field by using the following template:
      "ParamName": {
        "key": "ParamName",
        "value": {
          "stringValue": "$ParamName$"
        }
      }
      
  3. To upload the integration version, make a call to the projects.locations.integrations.versions.upload method with the updated integration version file.

Error handling strategy

An error handling strategy for a task specifies the action to take if the task fails due to a temporary error. For information about how to use an error handling strategy, and to know about the different types of error handling strategies, see Error handling strategies.

Quotas and limits

For information about quotas and limits, see Quotas and limits.

What's next