PowerApp Patch function is a function that is used for creating a record or modifying one or multiple records in the data source by not affecting the other present properties in PowerApps. A user can simply use the patch along with other powerAPp functions for creating records as well as modifying it later according to the need. In this article, we will be discussing the patch function, its syntax, and examples. We will also discuss in detail how to create and then modify the records using the patch() function. Then, in the end, we will discuss creating multiple records using the patch().
The patch() function in PowerApp is a function that is used for creating a record or modifying one or multiple records in the data source by not affecting the other present properties in PowerApps. A user can simply use the patch along with other PowerApp functions for creating records as well as modifying it later according to the need. There are a lot of features of the patch() function. Some of them are listed below:
Become a PowerApps Certified professional by learning this HKR PowerApps Training!
The syntax for patch() function is:
Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])
Where:
1. Filter the existing records for modification
2. If the record is found in the data source, the user will be able to modify it.
3. If the record is found in the default section, the user will be able to create it.
Check out our Latest Tutorial video. Register Now PowerApps Online Course to Become an expert in PowerApps.
Let us say, for example, that the user wants to modify the name of the employee to Sanjay from the record. The record will only be updated if it is already present in the data source, otherwise, a new record will be created.
Patch( Employee, First( Filter( Employee, Name = "Sanjay" ) ), { Phone: "986-8454-8900" })
A user can also use defaults() for the creation of a fresh record in the data source. Let us find the syntax for the same below:
Patch( Employee, Defaults (Employees), {Name = "Sanjay"} )
A user can patch function in power Apps and further use the Defaults() function for creating a new record for the Data source. The defaults function can never be used outside the patch function. It will always be used inside. This function helps in creating a base record that further helps the user to update the required columns with the values that the user provides.
Note: The user will be able to at least fill the required fields with the input values. Therefore, the user will be able to fill the other columns also using blanks.
Let us see the formula below and create a new record for an employee’s information.
Patch(‘Employee Info’, Defaults(‘EmployeeInformation’), {FirstName:”Sanjay”,LastName:”Sharma”,Mobile:45362829477})
The return value for the record is defined for the record which is either created or modified. It is then stored in a variable
Let us see the program below and understand the representation of the patch() function in the PowerApps Patch for modification of a record in the data source.
Patch( Data_Source, BaseRecords_Table, ChangeRecord_table1 [, ChangeRecord_table2, … ] )
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”Patch No”,Mobile:65743838})
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”test_date”, DOB ‘:Date(2021,6,22)})
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”test No/Yes”,isActive: true})
Choices([@’Employee_Info’].Job_Title)
Patch(‘Employee_Info’,Defaults(‘Employe_Info’),{Title:”test lookup”,’Office_Name’:{Id:Drop-down1_1.Selected.ID,Value:Drop-down1_1.Selected.Title}})
Want to know more about PowerApps,visit here PowerApps Tutorial!
Let us see the example below and understand how multiple records using the patch() and ForAll() work:
// Creating a new Collection
ClearCollect(TemperatureCollection, Weathers);
ForAll(
TemperatureCollection,
Patch(
Weathers
First(
Filter(
Weathers,
Humidity > 75 && Temperature <> 97
)),
{Temperature: 97}
)
)
Top 30 frequently asked PowerApps Interview Questions!
Conclusion:
In this article, we have talked about the patch() function in power apps. The patch() function in PowerApp is a function that is used for creating a record or modifying one or multiple records in the data source by not affecting the other present properties in PowerApps. A user can simply use the patch along with other PowerApp functions for creating records as well as modifying it later according to the need. We have discussed the features of the patch() function along with how to create a new record as well as modify it using different functions.
Related Articles:
Batch starts on 26th Sep 2023, Weekday batch
Batch starts on 30th Sep 2023, Weekend batch
Batch starts on 4th Oct 2023, Weekday batch
A user can patch() a new power app record using defaults() function.
When the user designs a patch form and he wants to submit the data, he uses the patch() function instead of submitting to create the form.
The patch() function in PowerApp is a function that is used for creating a record or modifying one or multiple records in the data source by not affecting the other present properties in PowerApps
It is used for creating a context- variable in power apps containing information like the number of button clicks, etc.