PowerApps Patch

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().

PowerApps patch function

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:

  • Patch() function can only create a single record at one time.
  • Patch() function can modify only one record at a single time.
  • In case the user wants to create or modify multiple records at one time, then he needs to use ForAll() function along with patch(). 
  • A user needs to first create a default record and then he can create a new record using the patch() function.

  Become a PowerApps Certified professional by learning this HKR PowerApps Training!

Power apps patch function syntax

The syntax for patch() function is:

Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])

Where:

  • DataSource - This field is always required where the user inputs the data source that he wants to add. If the data doesn't already exist, then a new source is added to the collection. 
  • BaseRecord - This field is always required where the user can:

           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.

           

Powerapps Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

PowerApps patch example

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"} ) 

Powerapps patch function

Create a record:

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 

Modify a record:

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, … ] ) 

PowerApps Patch functions

  • PowerApps Patch function number field: This function is used for patching a number field in the power apps. The syntax is written below:
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”Patch No”,Mobile:65743838})
  • PowerApps Patch function date: This function is used for setting a value to a date field and corresponding current time to it. The syntax is written below:
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”test_date”, DOB ‘:Date(2021,6,22)})
  • PowerApps Patch function Yes/No column: This function is used for checking if the function returns true or false. The syntax is written below:
Patch(‘Employee Info’,Defaults(‘Employee_Info’),{Title:”test No/Yes”,isActive: true})
  • PowerApps Patch function choice field: This function is used for patching a record in the chosen field. The syntax is written below:
Choices([@’Employee_Info’].Job_Title)
  • PowerApps Patch function with lookup: This function is similar to the choice field function provided the user needs to fill the id as well as the values field also. The syntax is written below:
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!

Subscribe to our youtube channel to get new updates..!

PowerApps Patch multiple records using Patch and ForAll

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}

)

)

PowerApps Patch

Top 30 frequently asked PowerApps Interview Questions!

Powerapps Training

Weekday / Weekend Batches

 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:

Find our upcoming Powerapps Training Online Classes

  • Batch starts on 26th Sep 2023, Weekday batch

  • Batch starts on 30th Sep 2023, Weekend batch

  • Batch starts on 4th Oct 2023, Weekday batch

Global Promotional Image
 

Categories

Request for more information

Amani
Amani
Research Analyst
As a content writer at HKR trainings, I deliver content on various technologies. I hold my graduation degree in Information technology. I am passionate about helping people understand technology-related content through my easily digestible content. My writings include Data Science, Machine Learning, Artificial Intelligence, Python, Salesforce, Servicenow and etc.

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.