Map task definition object

Map task (identified by "type": "Map") causes the system to process all the elements of an array, with the processing of each element independent of the others.

The Map Task applies a single workflow to multiple input elements, while the Parallel Task applies multiple different workflow branches to the same input.

Consider the following input data:

{
  "messages": [
    {
      "message": "Hi Ben, your order is on its way! Thank you for shopping with us.",
      "mobileNumber": "+61491571804"
    },
    {
      "message": "Hi Richard, your order is on its way! Thank you for shopping with us.",
      "mobileNumber": "+61491578888"
    }
  ]
}

Suppose it is desired to send a SMS message to each of the elements of the "messages" array using a third party SMS gateway API. Here is an example of an appropriate Map task.

"Send All Messsages": {
  "type": "Map",
  "itemsExpression": "${messages}",
  "itemProcessor": {
    "startTask": "Send SMS Message",
    "tasks": {
      "Send SMS Message": {
        "type": "Http",
        "credentials": "CredentialsId",
        "inputParameters": {
          "action": "Action=Publish&Message=${jsonata:$encodeUrl(`swf:item`.message)}&PhoneNumber=${jsonata:$encodeUrl(`swf:item`.mobileNumber)}&MessageAttributes.entry.1.Name=AWS.SNS.SMS.SenderID&MessageAttributes.entry.1.Value.DataType=String&MessageAttributes.entry.1.Value.StringValue=SimWorkflow&Version=2010-03-31&AUTHPARAMS"
        },
        "httpRequest": {
          "url": "https://sns.ap-southeast-2.amazonaws.com/?${action}",
          "method": "GET"
        },
        "end": true
      }
    }
  },
  "end": true
}

In the example above, the "Send SMS Message" will be executed once for each element of the "messages" field. The input to first iteration will be:

{
  "swf:item": {
    "message": "Hi Ben, your order is on its way! Thank you for shopping with us.",
    "mobileNumber": "+61491571804"
  },
  "swf:itemIndex": 0
}

The Map task has following additional fields:

Field

Type

Required

Description

itemsExpression

String

Yes

JSONPath expression to lookup reference data for an array of elements to process.

itemProcessor

JSON Object

Yes

The object MUST contain fields named "tasks" and "startTask" whose meanings are exactly like those in the top level of a Workflow definition object.

If any item fails, the entire Map task is considered to have failed and all the items are terminated. The system will terminate the workflow with an error.

maxConcurrency

Integer

No

An integer that provides an upper bound on how many tasks may run in parallel. Default is no limit.

maxConcurrencyExpression

String

JSONPath expression to lookup reference data for max concurrent tasks.

The output of Map task is a JSON Object with the "items" JSON array field, where each item is the output of an iteration.