Four (04) Primary Functions in Power Apps To Change Data in Data sources. - Cloud Limitations

Four (04) Primary Functions in Power Apps To Change Data in Data sources.

 


The four primary functions to change data in data sources are patch submit form update and update if each of these functions has its unique use cases and advantages so knowing when to use each one is crucial for efficient app development.

PATCH FUNCTION

the first one is patch patch is a super function that allows you to update or create a singular record in a data source it's perfect when you need to update specific Fields without using a form.

 When to use it ? only when you need to update or create a record without a form or when you need to update multiple records with different data or when you need to update just a subset  of fields in a record.

 Here is how to use it : 

On Select Property of patch button you can see this logic 

Patch(Restaurant,LookUp(Restaurant,ID=1),{Title:TextInput1.Text})

 if you want to create a new record only add defaults function as second parameter in patch function plus the data source inside its bracket and then the record you want to create 

Patch(Restaurant,Defaults(Restaurant),{Title:TextInput1.Text})

 As in the following capture 


if you want just to update a record you need first to find it for example you can in this case use LoockUp function to find a record and then update it 

Patch(Restaurant,LookUp(Restaurant,ID=1),{Title:TextInput1.Text})

SUBMITFORM FUNCTION

submit is your go-to function for submitting data from a form control to the data source it handles validation and error reporting automatically making it perfect for forms.

When to use submitform? when you submit entire form data to the data source or when you need builtin form validation and error handling. And here is how you can use :




SubmitForm is the easiest one, on Select Property of submit form button you can see that there is only submitform and the name of the form I want to submit and the form here named Form1, that's simple.  of course without ignoring or forgetting that our form is connected to a data source.




 So submitform just takes all the values in the fields of the form and submits them to the data source to which the form is connected.

UPDATE FUNCTION

Update is used to modify an existing record in a data source by replacing the entire record, it's less flexible than patch but can be handy in certain scenarios.
When to use update? when you replace an entire cord with a new one or when you update specific item in collections and here is how you can use it:


On Select Property for update button you can see this logic : 

Update(Restaurant,LookUp(Restaurant,ID=1),{Title:TextInput1_1.Text})

Update function, the data source, lookup function to find the record and then update or replace it.

UPDATEIF FUNCTION

UpdateIf is perfect for updating one or more records based on a condition, it's excellent for bulk updates where specific conditions are met. when to use updateif? when you update multiple records that meet a specific condition or when you update records based on a filter criteria.

How to use updates? here is how you can use it:


 you can see that updateif function needs a condition to be met and here if the ID for the record is equal to one then update the record.


These four functions are crucial for efficient developpemnt app in power apps, and understanding each one of them make you a power apps maker versatile.