web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Array to Strings with different numbers of items

(0) ShareShare
ReportReport
Posted on by 160

Hello,

I try to convert an array to strings, each array item has to become a separate string.

 

The array comes from a multiple choice field (max 4 items) in sharepoint. The selected items of this choice field should be stored as a string depending on the ID of the item. I have 4 strings with pre defined value (text0, text1, text2 and text3).

 

Example: only ID 0 + 1 + 3 have been selected, so that I want string text2 to be empty. It is also possible that  only one item has been selected (so 3 strings have to become empty), or even none (with all strings empty).

 

 

[
 {
 "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 "Id": 0,
 "Value": "text0"
 },
 {
 "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 "Id": 1,
 "Value": "text1"
 },
 {
 "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 "Id": 3,
 "Value": "text3"
 }
]

 

 

Maybe there is a simple way to solve this, but I cannot find the forest due to too many trees...

 

Thanks for your help

Paul

I have the same question (0)
  • Rhiassuring Profile Picture
    8,690 Moderator on at
    Re: Array to Strings with different numbers of items

    Hi there,

     

    So if the text is pre-defined, and it's 4 items only, I'd probably just use a switch.

    Rhiassuring_0-1700604289457.png

     

    Parse JSON, get the value, a "case" for each of the 4 values, and then (instead of Compose, which is what I show here), set the variable to whatever is appropriate for that text.

     

    Btw, if you get issues with your @OData,  escape it using @@. 

     

  • grantjenkins Profile Picture
    11,059 Moderator on at
    Re: Array to Strings with different numbers of items

    Can you explain exactly what you are trying to achieve as an end result? Are you retrieving items from a list and wanted to output the multi-choice selected values for each item in the list as a comma separated string? Just wondering why you would want to output the values to multiple variables.

     

    Maybe if you show what you currently have in your flow and exactly where you are having the issue, that would help.

  • Chriddle Profile Picture
    8,319 Super User 2025 Season 2 on at
    Re: Array to Strings with different numbers of items

    Chriddle_0-1700651621402.png

    From:

    range(0, 4)

    Map:

    coalesce(
    	first(
    		xpath(
    			xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    			concat('//Item[Id="', item(),'"]/Value/text()')
    		)
    	),
    	''
    )

    Chriddle_1-1700651694035.png

     

  • polo1604 Profile Picture
    160 on at
    Re: Array to Strings with different numbers of items

    Hi,

    thanks for your quick reply. I get this error after the select action:

     

    The execution of template action 'Select' failed: The evaluation of 'query' action 'where' expression '@coalesce(
    	first(
    		xpath(
    			xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    			concat('//Item[Id="', item(),'"]/Value/text()')
    		)
    	),
    	''
    )' failed: 'The template language function 'json' parameter is not valid. The provided value '{"Root":{"Item":}}' cannot be parsed: 'Unexpected character encountered while parsing value: }. Path 'Root.Item', line 1, position 16.'

     

    Probably due to the fact that my input contains the "@odata.type...." ?

     

    best regards

    Paul

  • Chriddle Profile Picture
    8,319 Super User 2025 Season 2 on at
    Re: Array to Strings with different numbers of items

    Yes, remove these with a Select.

  • polo1604 Profile Picture
    160 on at
    Re: Array to Strings with different numbers of items

    Hi,

     

    I cannot show my flow because all what I tried failed 🙂

     

    I need as a result from zero to 4 separate strings, (text0, text1, text2 and text 3), depending of which items has been selected in the multiple choice field in my sharepoint list.

     

    Sometimes no items selected, than 4 empty strings

     

    but also 1 or 2 or 3 or 4 items selected, and then the according text : ID=0 -> text0, ID=1 -> text1 and so on. If item 0 + 1 + 3 is selected, I want to get text0 + text1 + text3, and text2 needs to be empty.

     

    I hope I could explain it better.

     

    Best regards

    Paul

  • polo1604 Profile Picture
    160 on at
    Re: Array to Strings with different numbers of items

    how can I do this?

  • Chriddle Profile Picture
    8,319 Super User 2025 Season 2 on at
    Re: Array to Strings with different numbers of items

    Chriddle_0-1700725506592.png

    From: Your original array

    Map Id: item()['Id']

    Map Value: item()['Value']

  • polo1604 Profile Picture
    160 on at
    Re: Array to Strings with different numbers of items

    Hi @Chriddle 

    thanks for all your time an patience, something goes wrong:

     

    [
     {
     "ID": "0",
     "Value": "text0"
     },
     {
     "ID": "1",
     "Value": "text1"
     },
     {
     "ID": "3",
     "Value": "text3"
     }
    ]

     

    So I get this in the select action:

     

    [
     "",
     "",
     "",
     ""
    ]

     

     

    How can I get integer instead of string in the Id ?

    best regards

    Paul

  • Chriddle Profile Picture
    8,319 Super User 2025 Season 2 on at
    Re: Array to Strings with different numbers of items

    "Id" is case sensitive.

     

    To convert back to Integer use function int(<value>)

    Map Id: 

     

     

    int(item()['Id'])

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 722 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 461 Moderator

#3
developerAJ Profile Picture

developerAJ 283

Last 30 days Overall leaderboard