cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
co21
New Member

Add dynamically new properties to existing array power automate

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:

Capture0.PNG

HTTP action:

Capture1.PNG

Assgin Value to varArrayLineExtraObj:

orderLines is an Array

Capture3.PNG

Loop:

Capture4.PNG

 

 

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!

1 REPLY 1
eliotcole
Super User
Super User

Hi, @co21, I think that you have two options based on what you have said so far.

 

addPropertiesDemo001-Setup.jpg

( originalObject here represents your html response, you may need to add levels to get to ?['orderlines'] )

Add Extra Fields With Bespoke Information

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.

 

Simpler Method - Add Blank Fields

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:

text view.jpg

 

You could include *some* customisation there, but it would start to get complex.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,355)