cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Converting XML data issues

I have a flow set up that receives XML data from an API. If it returns only one item, it comes as an object, if more than one item, it's an array. My mind is going blank for the right expression. How would I add a condition that says 'if it's an object do something' otherwise 'if it's an array, loop through them'.

3 REPLIES 3
v-litu-msft
Community Support
Community Support

Hi @Anonymous,

 

There is no action or function that could determine an item is an array or object.

As a workaround, you could use the length() function to determine it, if the item is an object, it will fail, and you can make a branch to make the Flow could run when the length() function failed; if the item is an array, it will return a number, then Flow will go to the right side of array.

Annotation 2020-06-17 141548.jpg

 

Annotation 2020-06-17 141604.jpg

 

Annotation 2020-06-17 141615.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you. I thought I had tried that but I realized I hadn't added it into its own variable if it failed. 

Hi @Anonymous,

 

Yes, the short of workaround is every time the flow will report an error no matter it is an object or array.

 

I just thought of another way is convert the data into a string, then use contains() function to check it whether contains "[" and "]", because an array must contain "[" and "]", for example:

Annotation 2020-06-19 162834.jpg

 

contains(string(outputs('Compose')),'[')

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,162)