JavaScript

Runs an arbitrary JavaScript function.

Inputs

Function Code

The JavaScript code. This must contain a function named run:

function run() {
  // code goes here
}

The function receives two parameters:

  • input - An object that contains the value's of the components configured Parameters.
  • context - An object that contains methods for logging values and sending HTTP requests.

The default code demonstrates the usage of these parameters:

function run(input, context) {
  // Get your input parameters:
  // input.abc
  // input['abc']

  // Output logs
  // context.logger.info('message1');
  // context.logger.warn('message2');
  // context.logger.error('message3');

  // Invoke HTTP request:
  // const response = context.http.get('https://www.yourwebsite.com/api/abc');
  // context.logger.info(response.body);
  // const requestOptions = {
  //   headers: {
  //     'Content-Type': 'application/x-www-form-urlencoded',
  //     body: 'field1=value1&field2=value2'
  // };
  // response = context.http.post('https://test.test/test-post', requestOptions);
  return {
    myresult1: "value1",
    myresult2: 123,
  };
}

Parameters

A list of parameters the function receives at runtime via the input object.

Name

The name of the parameter.

You can use this name to access the parameter:

function run(input, context) {
  // input.myCustomParameter
  // input['myCustomParameter']
}

Value

The value of the parameter.

Output Schema

A JSON Schema that defines the shape of the data returned by the function. This lets other steps in the flow reference the output of the function.

This is the default schema:

{
  "type": "object",
  "properties": {
    "myresult1": {
      "type": "string"
    },
    "myresult2": {
      "type": "number"
    }
  }
}

Outputs

The output is an object with a shape that's defined by its Output Schema field.