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

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!



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

Dual Super User
Dual Super User

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!



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
Did you attend MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’ve streamed the digital event live, or you're watching on-demand, claim your attendee badge to sport on your profile.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (5,106)