cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IoaPan
Frequent Visitor

String to Array

hi everyone,

 

for a workflow I need to get the approvers from an external SharePoint list.

 

When I add a 'Compose' with an Array format (["approver1@email.com", "approver2@email.com"]), it is recognized as an Array object, and I use the Componse in a 'For Each' loop.

 

But when I get exactly the same string (["approver1@email.com", "approver2@email.com"]) from a SharePoint item, it does not get recognized as an Array, and the 'For Each' loop breaks with the following error:

 

ExpressionEvaluationFailed. The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@outputs('Compose')' is of type 'String'. The result must be a valid array.

 

Any idea how I can fix it?

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @IoaPan,

 

@efialttes is correct, you could also use the json() function to convert the string into an array, for example:

Annotation 2020-03-17 130159.png

 

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.

View solution in original post

4 REPLIES 4
efialttes
Super User
Super User

Hi!

The reason is, Sharepoint List do not support Array type columns, so you will probably have stored it as a 'single line of text', that is treated as a string in Power Automate.

You need to convert it into an array first

Neither array() nor createArray() will work with such format, so I would try the following, lets see if it works:

-Initialize variable, name myArray, type array, assign as its value the column value output from your 'Get item'

 

If it does not work, I would suggest to use replace() to remove some characters and combine it with split() using comma as separator

split(replace(replace(replace(replace(outputs('Compose'),']',''),'[',''),'"',''),' ',''),',')

 

Not in front of my laptop, so I haven't been able to test it

 

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



v-litu-msft
Community Support
Community Support

Hi @IoaPan,

 

@efialttes is correct, you could also use the json() function to convert the string into an array, for example:

Annotation 2020-03-17 130159.png

 

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.

Lin Tu
You solution seems simpler than mine
Thanx for sharing!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi @efialttes,

 

Your many posts also enlighten me, learn from each other.

 

Best Regards,
Community Support Team _ Lin Tu

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

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

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (4,764)