Create X amount of tasks based on integration message

Wasd123
Tera Expert

Hello,

We have a customer we are developing some API and they want that in the incoming message (JSON) they ahve different sections, what is so far not an issue, except when it comes to the order creation, as it looks like this.

 

"Rows": [
        {
            "CustomerLineNumber": "10",
            "SKU": "762229",
            "Description": "X13 i7 Gen 3 A",
            "Unit": "PCE",
            "Quantity": 5,
            "Price": 11876.34,
            "ReqDeliveryDate": "2024-02-13",
            "BillToID": "PURCHASE"
        },
        {
            "CustomerLineNumber": "20",
            "SKU": "762229",
            "Description": "X13 i7 Gen 3 N",
            "Unit": "PCE",
            "Quantity": 5,
            "Price": 5535.65,
            "ReqDeliveryDate": "2024-02-13",
            "BillToID": "PURCHASE"
        }
    ],

so in the Rows section we may see 1 or 2 or as many orders as they need, and we would need the system to raise separate tasks for each. so in this example 2 of them. How could I achieve this? Right now the Scripted Rest API is rasing a catalog item, but it is rasing a single task only, and not sure how can we set iy up that it would raise 2.

2 REPLIES 2

SunilKumar_P
Giga Sage

Hi @Wasd123, You can check the length of the respons and then do the for loop something like below.

 

var requestBody = JSON.parse(request.body.data);
var orders = requestBody.Rows;
for (var i = 0; i < orders.length; i++) {
//Write your logic here
}

 

Regards,

Sunil

Thank you @SunilKumar_P , but this could only work in the scripted rest api as my understanding, so if now the api is triggering a catalog item, and the catalog item triggers a flow, so how could I add this to the api that it would work together with the flow or pass the value to the flow to raise x amount of tasks? or how to do that in the flow designer? sorry, just so far I worked with incidents when it comes to rest api's, and here with catalog item, if I wanted to see the variables I had to set the api to trigger a catalog item as my understanding what it does, but from that moment the flow designer is taking over, or am I wrong?