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
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,717)