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 III
Super User III

@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.
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 III
Super User III

@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.
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 III
Super User III

@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.
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

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 III
Super User III

@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.
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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,535)