cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrendonBrooksP1
Post Patron
Post Patron

Updating a Collection after a Patch

Good evening. So far for my inventory app, I've been able to speed up performance dramatically by caching reference data that come from tables in my Azure SQL Database. A great tutorial for this is on @Meneghino page (i think its him) and it really helped. 

 

I used this formula to create my Collection in the OnStart property:

 

ClearCollect(CollectionName, '[dbo].[TableName]')

 

But what if I wanted to update a Collection after I Patch a record? How would I go about doing that? Would the following work

 

1. User clicks "Update Button"

2. Update Button does this:  

 

Patch('[dbo].[TableName]', First(Filter('[dbo].[TableName]', Id = Value(InspectId.Text))), {Base: DataCardValue12.Selected.Value, Location: DataCardValue44.Selected.Value, Unit: DataCardValue15.Selected.Value, Status: DataCardValue43.Selected.Value}); SubmitForm(EditItemForm) ClearCollection(CollectionName, '[dbo].[TableName]')

Does that significantly increase the amount of time the app has to save a record, update collection, load screen, display screen?

 

Brendon

 

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Community Champion
Community Champion

This is a start for iprovmement, and yes it is me...

Please note particularly how to refer to a record to update in the second argument of the Patch: you only need the primary key value(s) to identify a record uniquely...  It saves at least one read operation

 

Patch(
    '[dbo].[TableName]',
    {Id: Value(InspectId.Text)},
    {
        Base: DataCardValue12.Selected.Value,
        Location: DataCardValue44.Selected.Value,
        Unit: DataCardValue15.Selected.Value,
        Status: DataCardValue43.Selected.Value
        }
    );

ClearCollect(CollectionName, '[dbo].[TableName]')

View solution in original post

2 REPLIES 2
Meneghino
Community Champion
Community Champion

This is a start for iprovmement, and yes it is me...

Please note particularly how to refer to a record to update in the second argument of the Patch: you only need the primary key value(s) to identify a record uniquely...  It saves at least one read operation

 

Patch(
    '[dbo].[TableName]',
    {Id: Value(InspectId.Text)},
    {
        Base: DataCardValue12.Selected.Value,
        Location: DataCardValue44.Selected.Value,
        Unit: DataCardValue15.Selected.Value,
        Status: DataCardValue43.Selected.Value
        }
    );

ClearCollect(CollectionName, '[dbo].[TableName]')

Thank you. That worked magically. 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,962)