7 Ways To Use The PATCH Function In Power Apps (Cheat Sheet)

 

1. Create A New Record With Power Apps Patch Function



Syntax
Patch(Datasource, BaseRecord, NewRecord)


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false


Code
Patch(
    Employees,
    Defaults(Employees),
    {
        FullName: "Sarah Green",
        EmployeeNumber: 1002,
        HireDate: Date(2018,3,14),
        Active: true
    }
)Code language: CSS (css)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvind100203/14/2018true




2. Update An Existing Record Using Power Apps Patch Function



Syntax
Patch(Datasource, BaseRecord, ChangeRecord)


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvin100203/14/2018true


Code
Patch(
    Employees,
    LookUp(
        Employees,
        ID=4
    ),
    {
        FullName: "Sarah Brown",
        EmployeeNumber: 1003
    }
)Code language: JavaScript (javascript)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvind100303/14/2018true




3. Get The Result Of The Patch Function



Syntax
Set(VariableName, Patch(Datasource, BaseRecord, ChangeRecord))


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberCreatedCreated By
1Jaya Sankar105005/08/2022Matthew Devaney
2Ramesh Babu095805/10/2022Matthew Devaney
3Prasad Kilari056305/13/2022Matthew Devaney
4Arvind100205/13/2022Matthew Devaney



Code
Set(
    varEmployeeCurrent,
    Patch(
        Employees,
        Defaults(Employees),
        {
            FullName: "Kelly Smith",
            EmployeeNumber: 1066
        }
    )
)Code language: CSS (css)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberCreatedCreated By
1Jaya Sankar105005/08/2022Matthew Devaney
2Ramesh Babu095805/10/2022Matthew Devaney
3Prasad Kilari056305/13/2022Matthew Devaney
4Arvind100205/13/2022Matthew Devaney
5AshwinKumar106605/29/2022Matthew Devaney



varEmployeeCurrent record in Power Apps

{
    ID: 5,
    FullName: "Kelly Smith",
    EmployeeNumber: 1066,
    'Created By': Date(2022, 05, 29),
    Created: Matthew Devaney,
    Modified: Date(2022, 05, 29),
    Modified By: Matthew Devaney
}Code language: CSS (css)



4. Create Multiple New Records With Power Apps Patch Function



Syntax
Patch(Datasource, BaseRecordsTable, NewRecordsTable)


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvind        100203/14/2018true
5AshwinKumar106605/20/2022true




Code
ClearCollect(
    colNewEmployees,
    Table(
        Employees@{
            FullName: "Mary Baker",
            EmployeeNumber: 0798,
            HireDate: Date(2022, 06, 06),
            Active: true
        },
        Employees@{
            FullName: "John Miller",
            EmployeeNumber: 1203,
            HireDate: Date(2022, 06, 11),
            Active: true
        },
        Employees@{
            FullName: "Susan Wright",
            EmployeeNumber: 0590,
            HireDate: Date(2022, 06, 23),
            Active: true
        }
    )
);
Patch(
    Employees,
    ForAll(
        Sequence(CountRows(colNewEmployees)),
        Defaults(Employees)
    ),
    colNewEmployees
);Code language: JavaScript (javascript)



Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvin100203/14/2018true
5AshwinKumar106605/20/2022true
6Mangala D S079806/06/2022true
7Sudhamani D S120306/11/2022true
8Anitha D S059006/23/2022true




5. Edit Multiple Existing Records Using Power Apps Patch Function



Syntax
Patch(Datasource, BaseRecordsTable, UpdateRecordsTable)


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu095811/03/2015true
3Prasad Kilari056308/15/2013false
4Arvind 100203/14/2018true
5AshwinKumar106605/20/2022true


Code
ClearCollect(
    colUpdateEmployees,
    Table(
        Employees@{
            ID: 2,
            FullName: "Alice Henderson",
            EmployeeNumber: 1001
        },
        Employees@{
            ID: 4,
            Active: false
        },
        Employees@{
            ID: 5,
            HireDate: Date(2022, 08, 01)
        }
    )
);
Patch(
    Employees,
    ShowColumns(
        colUpdateEmployees,
        "ID"
    ),
    colUpdateEmployees
);Code language: JavaScript (javascript)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh Babu100111/03/2015true
3Prasad Kilari056308/15/2013false
4Arvind100203/14/2018false
5AshwinKumar106608/01/2022true




6. Upsert Multiple Records With Power Apps Patch Function



Syntax
Patch(Datasource, BaseRecordsTable, UpsertRecordsTable)


Input

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar105005/28/2010true
2Ramesh babu095811/03/2015true
3Prasad Kilari056308/15/2013false


Code
ClearCollect(
    colUpsertEmployees,
    Table(
        Employees@{
            ID: 2,
            FullName: "Alice Henderson",
            EmployeeNumber: 1001
        },
        Employees@{ 
            ID: Blank(),
            FullName: "Sarah Green",
            EmployeeNumber: 1002,
            HireDate: Date(2018, 03, 14),
            Active: false
        },
        Employees@{ 
            ID: Blank(),
            FullName: "Kelly Smith",
            EmployeeNumber: 1066,
            HireDate: Date(2022, 05, 20),
            Active: true
        }
    )
);
Patch(
    Employees,
    colUpsertEmployees
);Code language: JavaScript (javascript)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya sankar105005/28/2010true
2Ramesh Babu100111/03/2015true
3Prasad Kilari056308/15/2013false
4Arvin100203/14/2018false
5Ashwinkumar106608/01/2022true


7. Change Values In A Record Variable Using Power Apps Patch Function



Syntax
Patch(Record1, Record2)


Input

Record stored in a global variable named gblEmployee

IDFullNameEmployeeNumberHireDateActive
1Jaya sankar105005/28/2010true


Code
Patch(
    gblEmployee,
    {EmployeeNumber: 1063}
);Code language: CSS (css)


Output

Employees Table In SharePoint

IDFullNameEmployeeNumberHireDateActive
1Jaya Sankar106305/28/2010true




More Power Apps Patch Function Tips And Tricks

Want to learn more about the Patch function? Check out these awesome otherarticles I’ve written:


Everything You Need To Know About Power Apps Patch Forms

A full tutorial on how to build a Power Apps patch form including the topics: form submissions, data validation, error-handling and updating a previously submitted record.

Patch Multiple Records In Power Apps 10X Faster

A nifty trick I discovered to submit multiple records at once really really quickly.

Power Apps Patch Function Examples For Every SharePoint Column Type

Example of how to patch every SharePoint column type in an easy to read format.

Patch Function Error-Handling

Learn how to check a form for errors on submission and eliminate the possibility to losing entered data.

Power Apps Excel-Style Editable Table

Make an excel-style table in Power Apps you users will love by using the Patch function

Comments