
Announcements
I get response from an HTTP action and response is an Array like this :
{
"orderLines": [
{
"lineNumber": 1,
"productId": 100788762,
"brand": "test",
"productName": "productname",
"brandSku": "11-11-111",
"categories": [
{
"id": 31122,
"name": "Komponenter"
},
{
"id": 31134,
"name": "Audio"
}
],
"serialNumbers": []
},
{
"lineNumber": 2,
"productId": 100788232,
"brand": "test",
"productName": "productname",
"brandSku": "11-11-111",
"categories": [
{
"id": 31122,
"name": "Komponenter"
},
{
"id": 3134,
"name": "Audio"
}
],
"serialNumbers": []
}
]
}
And for each item i want add new properties (TrackandTrace,TrackandTracePath) like this :
{
"orderLines": [
{
"lineNumber": 1,
"productId": 100788762,
"brand": "test",
"productName": "productname",
"brandSku": "11-11-111",
"categories": [
{
"id": 31122,
"name": "Komponenter"
},
{
"id": 31134,
"name": "Audio"
}
],
"serialNumbers": [],
"TrackandTrace":"xxx",
"TrackandTracePath":"xxx"
},
{
"lineNumber": 2,
"productId": 100788232,
"brand": "test",
"productName": "productname",
"brandSku": "11-11-111",
"categories": [
{
"id": 31122,
"name": "Komponenter"
},
{
"id": 31134,
"name": "Audio"
}
],
"serialNumbers": [],
"TrackandTrace":"xxx",
"TrackandTracePath":"xxx"
}
]
}
Here is my flow :
Initialize New array:
HTTP action:
Assgin Value to varArrayLineExtraObj:
orderLines is an Array
Loop:
I know there is AddProperty , but how can i pass this properties dynamically TrackandTrace,TrackandTracePath to AddProperty and assgin them to each item in loop!
Hi, @co21, I think that you have two options based on what you have said so far.
( originalObject here represents your html response, you may need to add levels to get to ?['orderlines'] )
This will feel simpler or more logical to do which is why I'm mentioning it first. It also allows a semblance of automatic information to be included.
So, if you know that those keys will never change, then you can simply create a a Select action after the HTML request on the 'orderLines' array. Just add all the fields that are already there, and add two additional ones with the data that you need.
For each value you just add the relevant expression to pull that key from the old array. So for 'productId' that would be:
item()?['productId']
That looks at the item in the orderLines array and takes the value of the 'productId' field from it!
This would be super-fast in flow terms, and would allow you to then either process that elsewhere, or dynamically add additional information within that Select action.
For example, if the 'TrackandTrace' key is a combination of 'productId', two dashes, then the 'productName', then you'd use this in the value side:
concat(item()?['productId'], '--', item()?['productName'])
That would produce a "100788762--productname" value for your first item.
In my example, I also made the TrackandTracePath do this:
concat('/(', item()?['productId'], ')', item()?['productName'], '/TrackandTrace')
Which for the first item would produce a "/(100788762)productname/TrackandTrace" value in that field.
This would also be able to be done with unknown key names, too, and just inserting null 'TrackandTrace' and 'TrackandTracePath' keys, using something like this:
addProperty(addProperty(item(), 'TrackandTrace', null), 'TrackandTracePath', null)
To add that, you switch the You would add that using the 'JSON' view ("text mode") of the Select key/value pairs. The button is just to the right and looks like this:
You could include *some* customisation there, but it would start to get complex.