cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

5 REPLIES 5
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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
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. 

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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

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. 

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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

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

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (69,983)