1

I have a SharePoint list that contains a choice column with the 'multiple selection' option turned on. Each item in this list contains data related to preferences for a given user, and the choice column will store the IDs for each of the user's 'favorited' reports.

I would like to write a Patch formula in Power Apps that writes a new value to this column, but retains the existing values. Here is an extract from my current formula, triggered when a user selects the 'Add To Favorites' button, where 'Favorites' is the choice column that already contains values:

Patch(
            'Platform User Preferences',
            LookUp(
                'Platform User Preferences',
                UserEmail = User().Email
            ),
            {Favorites: [ThisItem.ID]}
        )

Current state, this formula overwrites the existing values in the choice column with the new single value, instead of adding it alongside the existing values.

One approach I have attempted (based on reading similar use cases online) is to create a collection from the Favorites column, add the new value to that collection, then patch the entire collection back to SP. However, I have had similar problems doing this as I do not fully understand the model of a collection that is based on a multi-value choice column. For example, the following also appears to completely wipe the data in the collection, rather than add to it:

ClearCollect(favslist,Filter('Platform User Preferences',UserEmail = User().Email).Favorites);
Collect(favslist, {Value: ThisItem.ID});

Any help with solving this problem would be most appreciated!

Chris
  • 33
  • 5

1 Answers1

0

You'll need to create another collection that contains each selection of the existing favorites. Right now your 'favlist' collection contains one item that contains all the existing favorite selections, then youre adding you new item. This isn't formatted correctly this way. Try updating your existing code before you patch, by using a ForAll and collect the existing items:

ClearCollect(existingfavslist,Filter('Platform User Preferences',UserEmail = User().Email).Favorites);
ForAll(existingfavlist, Collect(favslist, ThisRecord.Value));
Collect(favslist, {Value: ThisItem.ID});

Then just patch your collection 'favslist' to the list

JBerg
  • 411
  • 1
  • 3