Hello.
I am using Power Automate to pull in all some records. I am using the HTTP Action to pull in service now records, which works and it outputs my results as below
Now i need to loop through each result and return some data. Inside each json result, there is a description, the description contains some information which i need to use to do a condition. The description contains in the following format
FirstName : John,
Last Name : Smith,
ID Number : 1234,
I have tried to do a For Each loop, but i get the following error :
"The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('HTTP')' is of type 'Object'. The result must be a valid array."
Which actually makes sense, i cant loop through a string.
Can someone help me achieve my goal here? Which is loop through each item and return the description.
Then i want to put a condition to say if the description to say if ID = 12, then do this.
Thanks in advance.
Solved! Go to Solution.
I'm guessing you want body('HTTP')['result'] and loop through that instead. But if you could post the JSON sample (the actual JSON). Then one of us can tell you in a snap.
Hi @Vstar19
I believe you need to use something like item()?['FirstName'] or in your case item()?['ID Number'].
To test you are getting an output in your apply to each you can temporarily include a compose action and then check back on the history.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here
Where do i use that expression.?
Essentially, i want to loop from a json file.
I tried to use that expression in the for each , but i get an error the same error as above about it not being a valid array.
Can you post a sample of the JSON output from the HTTP Request? If you are using the "Body" then it will contain other data besides your json array most likely.
Here is a sample of the data.
There are several records, as you can see just under result, there is a 0, then the next record is 1,2 and so forth.
My aim is to a for each where by i can loo through each results (0,1,2,3,4), extract some data from a column called 'Description'. (This is not shown on the screenshot), but essentially, the description column contains a number i need.
I then would like to get that number from the description filed and use it as a condition to do a check aganist another number i have.
When i try to put the body of the json in a ForEach i get the error Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('HTTP')' is of type 'Object'. The result must be a valid array.
This is where i am getting stuck.
Thanks.
can anyone assist?
i am still unable to loop through each item from the JSON, i get the error "Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('HTTP')' is of type 'Object'. The result must be a valid array"
I want to loop through each item and return the description.
Thanks
@Vstar19 you could try create an array with the createarray() expression and then use your original expression?
It's hard to attempt the same with a screenshot, would need a copy of your array to be 100%
Damien
I'm guessing you want body('HTTP')['result'] and loop through that instead. But if you could post the JSON sample (the actual JSON). Then one of us can tell you in a snap.
@Paulie78 Thank you.
It was such a silly mistake i was making. I was trying to loop through a body('HTTP')?['result']?[0]?['number'] and it kept failing.
The solution was body('http')?['result'] as you said.
Such a novice mistake.
Thank you both for your help.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
13 | |
11 | |
9 | |
7 | |
6 |
User | Count |
---|---|
21 | |
21 | |
17 | |
8 | |
8 |