cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
famastefano
Regular Visitor

Patching inside gallery with toggle control updates more rows instead of 1

Hello,

as the title says, I have a toggle control inside a Gallery that basically says "Has the customer attended the event?", and allows the user to simply say "Yes, they did", "No, they didn't".

 

But, when a user clicks on the toggle, switching it to True, it updates all the other records...

 

Steps to reproduce:

  1. Create a new SharePoint List, "Sessions" with:
    1. Title, text
    2. Date, DateTime
  2. Create a new SharePoint List, "Attendees" with:
    1. Title, text
    2. HasAttended, YesNo
    3. AttendedDate, DateTime
    4. SessionID, Number (integer)
  3. Create a gallery with the list of "Sessions", sessionGallery
  4. Create a gallery with the list of "Attendees", attendeesGallery with a toggle.
  5. sessionGallery.OnSelect

 

 

 

UpdateContext({SelectedSession: ThisItem})

 

 

 

      6. attendeesGallery.toggle.Default

 

 

 

ThisItem.HasAttended​

 

 

 

      7. attendeesGallery.toggle.OnChange

 

 

 

// Also tried with OnCheck/OnUncheck to eliminate the If()
Patch(Attendees;
      ThisItem.ID; // also tried with LookUp(Attendees; ID = ThisItem.ID)
      {
          HasAttended: Self.Value;
          SessionID: If(Self.Value; SelectedSession.ID; Blank());
          AttendedDate: If(Self.Value; SelectedSession.Date; Blank())
      }
)​

 

 

     8. Select a session and then select multiple toggles to mark them as True

     9. Select another session, click on a single toggle to set it as False, multiple rows will be patched

 

 

I even tried with a dropdown or other controls to check if the problem were the gallery or the control itself, but it seems that Patching inside a gallery is not reliable.

1 ACCEPTED SOLUTION

Accepted Solutions
famastefano
Regular Visitor

So I successfully resolved the problem by removing the toggle and switching to a checkbox.

Guess I'll file a bug report if I'll find how to do it 😄

View solution in original post

6 REPLIES 6
C-Papa
Solution Supplier
Solution Supplier

Hi, try the below for the beginning of the patch, i have just edited your code above so i am assuming the columns names and if statements are correct

 

Patch(Attendees;{ID:ThisItem.ID};

{HasAttended: Self.Value;
SessionID: If(Self.Value; SelectedSession.ID; Blank());
AttendedDate: If(Self.Value; SelectedSession.Date; Blank())
}
)​

 

Alternatively you should also be able to do it by just using ThisItems e.g.

 

Patch(Attendees;ThisItem;

{HasAttended: Self.Value;
SessionID: If(Self.Value; SelectedSession.ID; Blank());
AttendedDate: If(Self.Value; SelectedSession.Date; Blank())
}
)​

v-qiaqi-msft
Community Support
Community Support

Hi @famastefano,

Do you want to update the record based on the Toggle value within current records?

Could you please share a bit more about the scenario?

Actually, it is a conflict saving issue. I have a test and the situation is confirmed on my side.

As an alternative solution, I think you could use a Radio button to replace the Toggle.

1). Insert a Radio button into the attendeesGallery

2). Set the Items property of the Radio1 button  as:

["Yes","No"]

    Set the Default property of the Radio1 button  as:

If(ThisItem.HasAttended=true,"Yes","No")

3). Set the OnChange property of the Radio1 button as below:

Patch(Attendees,
      attendeesGallery.Selected,
      {
          HasAttended: If(Radio1.Selected.Value="Yes",true,Blank()),
          SessionID: If(Radio1.Selected.Value="Yes", SelectedSession.ID, Blank())
      }
)

Check if this could solve your problem.

Regards,

Qi

Best Regards,
Qi

Thanks, but I already tried that solution and it doesn't work 😞

Hi @famastefano,

If this could not solve your problem, please describe more details about your need, do you want to patch the session id and date to Attendees when the toggle is true and remove the records when the toggle is switched to false?

Or could you please tell me that where did my solution not work, it could not patch the records in the current item or anything else? What's more, I think a screenshot could be much more efficient.

Regards,

Qi

Best Regards,
Qi

Hi,

the scenario is simple, the Customer wants to mark people as "Attended the event during that specific session", they imagined a "kind of a switch button to easily say 'yes/no' if they attended or not", so we implemented the behaviour with the toggle control.

 

I guess the problem is that we are triggering the Patch inside toggle.OnChange and PowerApps has a broken event listener wired to multiple controls while it should have done it only on that specific toggle, instead of the entire gallery.

 

The problem might also be the OnChange itself!

I didn't mention it, but the Customer also wants a button "Mark all as attended", so we created a button that does exactly that:

// Get all the attendees to mark as attended
ClearCollect(collAttendees, Filter(Attendees, HasAttended = false));
// Simplified version
ForAll(collAttendees As Attendee, Patch(Attendees, Attendee; { HasAttended = true })

This is executed outside the gallery, in a separated button, yet it triggers the gallery's toggle.OnChange!

 

I'll try with your solution to check if it works, thanks.

famastefano
Regular Visitor

So I successfully resolved the problem by removing the toggle and switching to a checkbox.

Guess I'll file a bug report if I'll find how to do it 😄

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

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,810)