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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Converting combo box s...
Power Apps
Answered

Converting combo box selected items to array in collection

(0) ShareShare
ReportReport
Posted on by 4

Hello,

I am trying to convert the selected items of my combo box into an array that can be put into a collection. 

Here is what my JSON Object looks like:

ClearCollect(myCollection, 
{
 someKey: "someValue",
 someArray: ["VALUE1", "VALUE2", "VALUE3"]
}

I want someArray to be populated with values from my combobox called aCombobox that gets its items from a dataverse table called "Status", and uses the values from the column 'cr0fa_status'.

 

Here's how I'm attempting to do this currently:

Set(myVar2, Concat(aCombobox.SelectedItems, Char(34) & 'Status (cr0fa_status)' & Char(34) & ","));
Set(trimmedStatuses, Left(myVar2, Len(myVar2)-1));

 What this yields into trimmedStatuses is: "INREV","INPROG"

where inrev and inprog are statuses from the status table.

 

However, when I try to put this into a collection by doing: 

ClearCollect(myCollection, 
{
 someKey: "someValue",
 someArray: [trimmedStatuses]
}

and then converting that collection to JSON, I end up with this JSON structure:

{
 "someKey": "someValue",
 "someArray": [
 {
 "Value": "\"INREV\",\"INPROG\""
 }
 ]
}

I do not want to have the "Value" key, and i just want it to be: "someArray": ["INREV","INPROG"]

 

So, my overall question is how do I convert the SelectedItems into a JSON array object so that it looks correct in my end JSON payload.

How do I 

Categories:
I have the same question (0)
  • Verified answer
    CarlosFigueira Profile Picture
    on at

    In Power Fx we don't have tables (arrays) of primitive types (such as strings or numbers) - all tables are made up of records, and if you have a table of primitive values such as [1, 2, 3], this actually represent a table of records {Value:1}, {Value:2}, {Value:3}. That means that the JSON function today, which can be used to serialize Power Fx objects, will not emit something like ["INREV","INPROG"]. There are plans to allow serialization of unwrapped records in the JSON function, but it's not in the product yet.

     

    For your scenario, one option is to perform the JSON serialization yourself, with something like the expression below

     

    Concatenate(
     "{",
     Concat(
     [
     { Name: "someKey", Value: JSON(someValue) },
     { Name: "someOtherKey", Value: JSON(someOtherValue) },
     {
     Name: "someArray",
     Value: "[" & Concat(aCombobox.SelectedItems, Char(34) & 'Status (cr0fa_status)' & Char(34), ",") & "]"
     }
     ],
     $"""{Name}"": {Value}",
     ","
     ),
     "}"
    )

     

    Hope this helps!

  • ThomasJazz Profile Picture
    4 on at

    Hi Carlos, thank you for your reply. I am trying to adapt the structure you've given to my project but have been getting errors with it. Does that concat formula you posted work for you? It's giving me the following error, and each time I try to fix it, another one pops up

    ThomasJazz_0-1709135927634.png

     

  • CarlosFigueira Profile Picture
    on at

    Sorry, there was a <<">> character (in the expression <<

    $"""{Name}"": {Value}",>>and a <<,>> character (after the last closing parentheses) missing in my expression. I edited the answer with the corrected code.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard