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

Checkbox & Patch Bug in Gallery

Hello all, 

 

I have a gallery set up with checkboxes to select and patch one or more records into a collection called "colCheckedRecords".  I then use a ForAll loop to do an updating or patching function on all the records found in my collection.  This largely works very well, but I am seeing an issue where the very last record I "Check" will indicate the record has been added to the collection but the patch does not occur.  

A little bit more info:  I'm using this to update a "status" column for each of the "Checked" records.  I'm usually selecting between 3 and 7 records in the gallery.  Only the last one does not patch my updated status to my SQL list.  

 

Any thoughts or ideas on this? 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@MaxEgn 

I would perhaps take a slightly different approach to this.  Since you are most likely using this in a Gallery (your CheckBox) instead use that as your collection (because it already is).

 

Your button OnSelect action formula would become this:

ForAll(
    Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
    UpdateIf('[dbo].[ActiveList]', Id = galItem.Id,
        {statusNumber: 
            Switch(CurrentUserDept,
                "Department1", 2,
                "Department2", 4,
                "Department3", 5
            ),
         UserModified: User().FullName,
         TimeModified: Now()
        }
    )
);

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@MaxEgn 
Can you provide some of the formulas you are using that are causing the issue?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
MaxEgn
Frequent Visitor

This is the only code associated with "On Check" of the checkbox.

 

Collect(colCheckedItems, ThisItem);

UpdateContext({Checkbox: true})

The Button that patches the collection code:

ForAll(
ShowColumns(colCheckedItems, "Id", "statusNumber"),
Patch('[dbo].[ActiveList]', ThisRecord,
Switch(CurrentUserDept,
"Department1", {statusNumber: 2},
"Department2", {statusNumber: 4},
"Department3", {statusNumber: 5},

{UserModified: User().FullName},
{TimeModified: Now()}
));


Clear(colCheckedItems);
UpdateContext({Checkbox: false});


It seems pretty straightforward so I'm not sure why there is this intermittent issue.  It seems to happen more when the clicks are faster, but it still only occurs every few times with 3 or more records. 

RandyHayes
Super User
Super User

@MaxEgn 

I would perhaps take a slightly different approach to this.  Since you are most likely using this in a Gallery (your CheckBox) instead use that as your collection (because it already is).

 

Your button OnSelect action formula would become this:

ForAll(
    Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
    UpdateIf('[dbo].[ActiveList]', Id = galItem.Id,
        {statusNumber: 
            Switch(CurrentUserDept,
                "Department1", 2,
                "Department2", 4,
                "Department3", 5
            ),
         UserModified: User().FullName,
         TimeModified: Now()
        }
    )
);

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

This solution does work for the first half of my function!  Thank you! 

However I do still have a need of doing the same functionality but patching the selected records from the gallery as a new record to a different database in addition to updating a column in my existing record. 

Is there a way to switch out "Update if" with an actual Patch function? I've been struggling with "incompatible type" errors for a while now. 

RandyHayes
Super User
Super User

@MaxEgn 

Good to hear things are progressing.

 

So, if it is that you need to instead put this into another datasource, then consider the following formula:

Collect(yourOtherSource,
    ForAll(
        Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
        Patch(Defaults(yourOtherSource),
            {statusNumber: 
                Switch(CurrentUserDept,
                    "Department1", 2,
                    "Department2", 4,
                    "Department3", 5
                ),
             UserModified: User().FullName,
             TimeModified: Now()
            }
        )
    )
);

I kept the original column names you had for the other list, but please adjust as needed.

This formula will create a table of all the new records you want, and then submit them to the other datasource in one function (collect).

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

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

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,140)