1

I have a sharepoint list that has a multiselect column. in powerapps I would like to make a collection of the selected values.

for example I have a multiselect column named category that have choices One, Two, Three, and Four. I have selected Two and Four.

my code in powerapps Integrated Form OnEdit is

Clear(myCollection); 
ForAll(Choices([@SMEList].Category), Collect(myCollection,ThisRecord.Value));

but that is giving me One, Two, Three and Four. I only want the selected Values (Two and Four)

Bryan Dellinger
  • 4,724
  • 7
  • 33
  • 79

2 Answers2

2

This works:

ClearCollect(colMyCollection,
    Filter(
        Choices('2022-05-23_StackOverflow'.SMEList),
        Or(
            ThisRecord.Value = "Choice 2",
            ThisRecord.Value = "Choice 4"
        )
    )
)

Illustrated:

enter image description here


EDIT 1

  • Ok. I changed the SP column to multiselect.
  • OnStart of the app, ClearCollect(colList, <SP_list_name>)
  • Insert a Gallery control, set its Items property to colList. Set its OnSelect property to Set(varRecord, ThisItem)
  • Insert a Form control, set its Item property to LookUp(colList, ID = varRecord.ID)

Illustrated

enter image description here


EDIT 2

RE: ...just get it from the sharepoint list .

  • Leave the OnStart function to ClearCollect(colList, SharepointList)
  • Gallery:
    • Leave the GalleryItems property to colList
    • Change the TextBox (in the Gallery) Text property to Concat(ThisItem.SMEList, Value, ",")
  • Form:
    • You already have the values from the Sharepoint list in the ComboBox. Its unclear to me why you to manipulate these values outside of the ComboBox.
    • How about just changing the DisplayMode property of the ComboBox to View.
    • Then its read-only

enter image description here

SeaDude
  • 3,725
  • 6
  • 31
  • 68
  • sorry I am a bit confused this looks like you do not have a multi select for your choices. my column is a multiselect of choices (one row can have more than one choice.) so for row 1 say I pick Choice 1 and Choice 4. for row 2 I pick Choice 2 and Choice 3. In the Power App Integrated form for Row 1 I want the collection to be Choice 1 and Choice 4 and for row 2 in the Power App Integrated form I want the collection to contain Choice 2 and Choice 3 (Nothing should be hardcoded) – Bryan Dellinger May 24 '22 at 17:41
  • Please see edit 1 – SeaDude May 25 '22 at 04:04
  • thanks actually that is the solution I am currently using but I was hoping to do it without having to have a combobox. and just get it from the sharepoint list but I don't think it is possible. I don't think you can get the selected values directly from the sharepoint list. – Bryan Dellinger May 25 '22 at 09:51
  • 1
    Please see edit 2 – SeaDude May 26 '22 at 14:30
  • thanks I am using a hidden combobox and a collection to populate checkboxes. I would love to not have to use the combobox (I am using checkboxes instead and I don't want or need a combobox) I was just wondering if it is possible to get the selected values into a collection directly from the sharepoint list WITHOUT having to use any kind of control (combobox, textarea etc.) like Filter(Choices([@SMEList].Category,selected) which I know isn't a thing. – Bryan Dellinger May 26 '22 at 16:04
  • 1
    `colList.SMEList` **IS** `...the selected values into a collection directly from the sharepoint list...` Good luck! – SeaDude May 26 '22 at 16:20
0

I'm going to assume that [@SMEList].Category indicates you have a Lookup column of "Category" on "SMEList".

You say you want a collection without using a combo box? Yet, you only want the selected values, so where are these getting selected, if not from a box? Even if you don't want the user to mess with the box, you can set it to disabled, view or visible = false. So I'm going to include that route and then also talk about getting the values from the list, directly.

Combo Box

Concat(ComboBox1.SelectedItems,Value,",")

or it might be:

Concat(ComboBox1.SelectedItems,Category,",")

This would let you pull all selected values together. So it would go:

Collect(myCollection,Concat(ComboBox1.SelectedItems,Value,","));
Collect(myCollection,Concat(ComboBox1.SelectedItems,Category,","));

Or, using the OnChange of the combo box:

ClearCollect( myCollection, ComboBox1.SelectedItems );

Automatically updating the collection whenever any selected items are changed.

(And in the App's OnStart, do Set(myCollection, []) as you probably already have.)

Without a combo box

You could also set the list into a collection from the beginning, in the App's OnStart, like:

Set(colList, []);
ClearCollect(colList, [@SMEList])

...and based on an ID, you call to that collection to get its values, like SeaDude demonstrated using a gallery and then he set a combo box using the result, basically the key was: LookUp(colList, ID = varRecord.ID)

Where varRecord was set to ThisItem from the list:

Gallery's OnSelect property: Set(varRecord, ThisItem)

...So it sets the item that the gallery was invoking. (And then he set that item equal to the combo box's Items property using that LookUp formula, above.)

But that code takes the collection with the list in it and lets you send in an ID and get the whole item, with all of its columns, back out. You can do a lot with a LookUp command just on its own if you are going against a list directly, and without an ID, too:

ClearCollect(myCollection,LookUp([@SMEList],'Created'<Today()).'Category')

...could potentially grab you every Category value on that SMEList that was Created before today. You can use any condition you want (ID equals something, Title equals something, etc.).

Either direction

After you get your collection, you can do a CountRows on your myCollection to see how many values it has to see if it matches what you expect:

Notify(CountRows(myCollection), NotificationType.Information)
vapcguy
  • 7,097
  • 1
  • 56
  • 52