cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mlaurie
Helper I
Helper I

LFH: FORALL function to look at each item in collection and process if condition is met, if not ELSE

Thanks for reading! So my example is similar to this. I have 10 users on a PowerApp screen looking at a gallery of available players to add to their team. They select one or more players and my command does the following:

 

ForAll(RenameColumns(playerslistcol,"ID","PlayerID"),
UpdateIf(SPDataSource,Status <> "Selected" && PlayerID=ID,{Status:"Yes",'Email Address':DataCardValue12.Text,'Position':Dropdown2.Selected.Value,'Team  Name':DataCardValue11.Text,'Phone Nbr':DataCardValue13.Text}));Clear(playerslistcol);UpdateContext({thankyou:true})

 

The trouble is if the status = Selected then it does nothing (i.e. someone else looking at the screen has selected that player first, but the second person has not 'seen' the update to the gallery which is filtering the status so they still appear.) The UPDATEIF processes any and all that are not already selected but then nothing else happens in the situation where one of the collection items does not meet the condition. I know you can't do a SET or UPDATECONTEXT in a FORALL, so I'm thinking there may be a solution backstream.  Any ideas?



1 ACCEPTED SOLUTION

Accepted Solutions

@mlaurie ,

One way could be to do a Lookup on the OnChange of the Selected drop-down

If(
   Lookup(
      YourListName,
      ID=ThisItem.ID
   ).Status = "Selected",
   Notify("This person has already been selected",NotificationType.Error,5000),
   Reset(Self)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

4 REPLIES 4
WarrenBelz
Super User III
Super User III

Hi @mlaurie ,

You cannot set a Variable in a loop, but if I am reading this correctly, you are interested in the gallery the user can see. If you add the PlayerID with RenameColumns when you create the gallery items, you could do this

ForAll(
   Filter(
      YourGalleryName.AllItems,
      Status=Selected
   ),
   UpdateIf(
      SPDataSource,
      Status <> "Selected" && PlayerID=ID,
      {
         Status:"Yes",
         'Email Address':DataCardValue12.Text,
         'Position':Dropdown2.Selected.Value,
         'Team  Name':DataCardValue11.Text,
         'Phone Nbr':DataCardValue13.Text
      }
   )
);
Clear(playerslistcol);
UpdateContext({thankyou:true})

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Thanks @WarrenBelz . Thanks for the response!

I should have made myself more clear about the gallery vs. the collection. When the screen appears, the gallery is populated with items that do not equal "Selected". The user then selects one or more and adds them to a collection (playerslistcol in the example). Once in the collection how do I get the collection to go look at each selected and find out if the status has changed to "Selected" in the time between adding it to the collection from the gallery.

@mlaurie ,

One way could be to do a Lookup on the OnChange of the Selected drop-down

If(
   Lookup(
      YourListName,
      ID=ThisItem.ID
   ).Status = "Selected",
   Notify("This person has already been selected",NotificationType.Error,5000),
   Reset(Self)
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

Hi @mlaurie ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power Apps User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (35,367)