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
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.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,621)