cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Franklin76
Frequent Visitor

Evaluating if Listbox Selected Items are in a Collection

I am creating an application that will work as an admin console for workflows processed in Power Automate. In one area of my application I have a list box that contains a set of tasks that are to be created by a particular workflow. These tasks are stored in the Dataverse. I am trying to figure out a way to update and display the tasks in a list box without commiting additions/deletions directly to the database, but using a save button that works for all the options available on the screen.

 

See my basic example below, where I have the list box, a text input, add & remove buttons and then save and cancel buttons on the bottom (there are other options on the screen, but those are not needed for this example).

powerapps add-remove.png

To do the add portion, I have the following.

  • A Collection (Items) that is loaded with values from the Dataverse 
  • A Collection (TempItems) that has entries loaded when you hit the add button 
  • A collection (AllItems) that is made up of the first two collections 

When the save button is pressed, values from TempItems are saved to the Dataverse.  The Items collection is reloaded with the values from the Dataverse and the TempItems collection is cleared.

 

This works fine for doing additions, but doing the Remove portion has proven to be more difficult than I expected.

 

What I am trying to do, is take the selected items from the ListBox and compare them against the Items and TempItems collections.  If a selected Item is in the TempItems collection, then I will just remove it from that collection.  If the selected Item is in the Items collection, I'll add that item to a 4th collection, DeleteItems.  Then, when the Save button is pressed, I'll remove the values in the DeleteItems from the Dataverse.

 

So my questions are:

  • Is this a proper approach for this type of behavior? If not, Any suggestions on a better approach for this?
  • If this is a proper approach, how can I check to see if the selected items from the listbox are in a collection? I haven't been able to figure out the proper way to get the selected Items to compare them against the values in the collections.
1 ACCEPTED SOLUTION

Accepted Solutions

I was able to get this resolved. Hope this helps someone out.  

 

  • Create a new collection of the tasks that should be deleted, by filtering my original Items collection with the selected items of the listbox (used collect and not clearCollect for situations where the remove button was used multiple times before hitting save)

 

Collect(DeleteItems,Filter(Items,cre0c_title in Listbox.SelectedItemsText.Value))​

 

  • Removed Items from my Items collection if they were in this new collection

 

RemoveIf(Items,cre0c_title in DeleteItems)

 

  • Removed Items from my TempItems Collection if they were selected in the Listbox

 

RemoveIf(TempItems,cre0c_title in Listbox.SelectedItemsText.Value)​

 

  • Reload the collection displayed in the listbox with the updated collections

 

ClearCollect(AllItems,TempItems,Items)​

 

  • When the save button was hit, remove the Items from the table in the DataVerse

 

RemoveIf(table name&gt,cre0c_title in DeleteItems)​

 

View solution in original post

2 REPLIES 2
PatrickMSFT
Microsoft
Microsoft

Franklin76,

 

Reads to me like you've got the right idea here, for reference:

Remove and RemoveIf functions - Power Apps | Microsoft Docs

 

I know these functions can be pretty particular, might have to tweak your expressions a bit based on the link. Not sure if you're running into any warnings or errors when you run this app.

 

Match might help, albeit it depends on what you've set up thus far:

IsMatch, Match, and MatchAll functions - Power Apps | Microsoft Docs

 

What happens when you try to run this and what are you running?

 

Let us know!

I was able to get this resolved. Hope this helps someone out.  

 

  • Create a new collection of the tasks that should be deleted, by filtering my original Items collection with the selected items of the listbox (used collect and not clearCollect for situations where the remove button was used multiple times before hitting save)

 

Collect(DeleteItems,Filter(Items,cre0c_title in Listbox.SelectedItemsText.Value))​

 

  • Removed Items from my Items collection if they were in this new collection

 

RemoveIf(Items,cre0c_title in DeleteItems)

 

  • Removed Items from my TempItems Collection if they were selected in the Listbox

 

RemoveIf(TempItems,cre0c_title in Listbox.SelectedItemsText.Value)​

 

  • Reload the collection displayed in the listbox with the updated collections

 

ClearCollect(AllItems,TempItems,Items)​

 

  • When the save button was hit, remove the Items from the table in the DataVerse

 

RemoveIf(table name&gt,cre0c_title in DeleteItems)​

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (89,644)