cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

Re: String to Array

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
Highlighted
Dual Super User III
Dual Super User III

Re: String to Array

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!



Highlighted
Community Support
Community Support

Re: String to Array

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

Highlighted
Dual Super User III
Dual Super User III

Re: String to Array

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!



Highlighted
Community Support
Community Support

Re: String to Array

Hi @efialttes,

 

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

 

Best Regards,
Community Support Team _ Lin Tu

Helpful resources

Announcements
FirstImage

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (4,649)