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

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

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

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

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