Data Transformer Script task

The Data Transformer Script task lets you write, edit, and evaluate custom Jsonnet templates to perform data mapping in your integration.

For information about the data mapping in Apigee Integration, see Data mapping overview.

Configure the Data Transformer Script task

To add a Data Transformer Script task to your integration, perform the following steps:

  1. In the Apigee UI, select your Apigee Organization.
  2. Click Develop > Integrations.
  3. Select an existing integration or create a new integration by clicking Create Integration.

    If you are creating a new integration:

    1. Enter a name and description in the Create Integration dialog.
    2. Select a Region for the integration from the list of supported regions.
    3. Click Create.

    This opens the integration in the integration designer.

  4. In the integration designer navigation bar, click +Add a task/trigger > Tasks to view the list of available tasks.
  5. Click and place the Data Transformer Script element in the integration editor.
  6. Click the Data Transformer Script element on the designer to view the Data Transformer Script task configuration pane.
  7. Click Open Data Transformer Script editor.
  8. The Data Transformer Script editor appears displaying a default commented Jsonnet template example.
  9. Write your Jsonnet code and close the editor once complete. Any changes will be autosaved.

Using the Data Transformer Script editor

You can use the Data Transformer Script editor to access the integration variables, perform variable assignments, and add or modify variables in your integration. The Data Transformer Script editor provides the following features to enrich your scripting experience:

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

To open the editor, go to the Data Transformer Script task configuration pane and click Open Data Transformer Script Editor.

The Data Transformer Script editor by default imports functions, a predefined custom library containing a set of Jsonnet functions for data mapping in Apigee Integration. For details of the available custom functions, see Data Transformer functions.

The following image shows the sample layout of the Data Transformer Script editor:

image showing data-transformer script editor image showing data-transformer script editor

Access integration variables

To read an existing integration variable from the Data Transformer Script editor use the extVar function from the predefined functions library.

Example: Read and update existing integration variables using the Data Transformer Script editor.

Jsonnet script

local f = import "functions"; // Import predefined Data Transformer function library

local str1 = f.extVar("inputVar1"); // Access integration input variable "Inputstr1" with value "Hello"
local str2 = f.extVar("inputVar2"); // Access integration input variable "Inputstr2" with value "World"
{
  OutputVar: str1 + " " + str2 + "!", // Write to Jsonnet output variable "OutputVar"
  "output-str-var": str1 + " Integration " + str2 + "!", // Write to Jsonnet output variable "output-str-var"
}

Output

image showing data-transformer script example image showing data-transformer script example

Best practices

For information about the usage limits that apply to the Data Transformer Script task, see Usage limits.