Sometimes processing interactive/synchronous APIs in M3 for a lot of data can be time consuming and since there are some limits in relation to timeouts, splitting the processing might make sense.

Create a batcher workflow

The purpose of this workflow is to:

Transform: Prepare the REST API request

Use a Transform step to prepare the request.

/* prepare m3 request */
{
    "request": {
        "program": "MNS150MI",
        "transactions": [
            {
                "transaction": "LstUserData"
            }

        ]
    }
}

Rest API: Perform the request

We’ve selected our M3 environment here

{
  "version": 2,
  "connectionId": "CONNECTION-d48003b118fc4384880e79779206e418",
  "endpoint": "{{ $context.connection.attributes.baseUri }}m3api-rest/v2/execute",
  "method": "post",
  "headers": {
    "content-type": "application/json"
  },
  "bodyPath": "$.request"
}

Transform: Batch the result

In here, we use the Vince specific JSONata function $chunk(array, size) to split the response into batches.

/* create batches of 50 requests */

(
    $records := $context.data.all.rest_api_1.body.results[0].records;
    $chunks := $chunk($records, 50);

    {
        "requests": $chunks.{
            "program": "MNS150MI",
	          /* within each chunk, for all USID fields, generate a transaction */
            "transactions": USID.{
                    "transaction": "GetUserData",
                    "records": {
		                    /* current context/"focus" is the USID value */
                        "USID": $ 
                    },
                    "selectedColumns": ["USID", "TX40"]
                }[]
        }
    }
    
)

Untitled

Code: Trigger the workflow