Baixe o app para aproveitar ainda mais
Prévia do material em texto
2023 7 Ways To Use The PATCH Function In Power Apps MATTHEW DEVANEY LAST UPDATED: 2023-07-04 https://www.matthewdevaney.com https://twitter.com/mattbdevaney https://www.linkedin.com/in/matthew-devaney-6499271b7/ Table Of Contents 2 Table Of Contents Introduction ........................................................................................................................................................................ 3 1. Create A New Record With The Patch Function ............................................................................................................. 4 2. Update Existing Record Using The Patch Function ......................................................................................................... 6 3. Get The Result Of The Patch Function ............................................................................................................................ 8 4. Create Multiple New Records With The Patch Function .............................................................................................. 10 5. Edit Multiple Existing Records Using The Patch Function ............................................................................................ 13 6. Upsert Multiple Records With The Patch Function ...................................................................................................... 16 7. Change Values In A Record Variable Using The Patch Function ................................................................................... 19 Introduction 3 Introduction Welcome to my guide on “7 Ways To Use The PATCH Function In Power Apps”. Power Apps PATCH function is the hardest function to understand. Why? The Patch function is the only function you can use 7 different ways. Yeah, you heard me right. Seven. That’s why I built a no-nonsense cheat sheet that you can use to quickly figure out how the patch function works. I hope you enjoy this free eBook. I don’t have ads on my site because I believe in delivering the best learning experience possible. This website is paid for out of my own pocket. If you’ve found value in the free resources I’ve created, I’d love to have your support. Click on the “Buy Me A Cat Treat” button below to support the site. Thank you! https://docs.microsoft.com/en-us/power-apps/maker/canvas-apps/functions/function-patch https://buymeacoffee.com/mattbdevaney 1. Create A New Record With The Patch Function 4 1. Create A New Record With The Patch Function Syntax Patch(Datasource, BaseRecord, NewRecord) Input Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false Code Patch( Employees, Defaults(Employees), { FullName: "Sarah Green", EmployeeNumber: 1002, HireDate: Date(2018,3,14), Active: true } ) 1. Create A New Record With The Patch Function 5 Output Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 2. Update Existing Record Using The Patch Function 6 2. Update Existing Record Using The Patch Function Syntax Patch(Datasource, BaseRecord, ChangeRecord) Input Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true Code Patch( Employees, LookUp( Employees, ID=4 ), { FullName: "Sarah Brown", EmployeeNumber: 1003 } ) 2. Update Existing Record Using The Patch Function 7 Output Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Brown 1003 03/14/2018 true 3. Get The Result Of The Patch Function 8 3. Get The Result Of The Patch Function Syntax Set(VariableName, Patch(Datasource, BaseRecord, ChangeRecord)) Input Employees table in SharePoint ID FullName EmployeeNumber Created Created By … 1 Matthew Devaney 1050 05/08/2022 Matthew Devaney … 2 Alice Lemon 0958 05/10/2022 Matthew Devaney … 3 David Johnson 0563 05/13/2022 Matthew Devaney … 4 Sarah Green 1002 05/13/2022 Matthew Devaney … Code Set( varEmployeeCurrent, Patch( Employees, Default(Employees), { FullName: "Kelly Smith", EmployeeNumber: 1066 } ) ) 3. Get The Result Of The Patch Function 9 Output Employees table in SharePoint ID FullName EmployeeNumber Created Created By … 1 Matthew Devaney 1050 05/08/2022 Matthew Devaney … 2 Alice Lemon 0958 05/10/2022 Matthew Devaney … 3 David Johnson 0563 05/13/2022 Matthew Devaney … 4 Sarah Green 1002 05/13/2022 Matthew Devaney … 5 Kelly Smith 1066 05/29/2022 Matthew 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 } 4. Create Multiple New Records With The Patch Function 10 4. Create Multiple New Records With The Patch Function Syntax Patch(Datasource, BaseRecordsTable, NewRecordsTable) Input Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true 4. Create Multiple New Records With The Patch Function 11 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 ); 4. Create Multiple New Records With The Patch Function 12 Output Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true 6 Mary Baker 0798 06/06/2022 true 7 John Miller 1203 06/11/2022 true 8 Susan Wright 0590 06/23/2022 true 5. Edit Multiple Existing Records Using The Patch Function 13 5. Edit Multiple Existing Records Using The Patch Function Syntax Patch(Datasource, BaseRecordsTable, UpdateRecordsTable) Input Employees table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true 5. Edit Multiple Existing Records Using The Patch Function 14Code 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 ); 5. Edit Multiple Existing Records Using The Patch Function 15 Output Employees table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Henderson 1001 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 false 5 Kelly Smith 1066 08/01/2022 true 6. Upsert Multiple Records With The Patch Function 16 6. Upsert Multiple Records With The Patch Function Syntax Patch(Datasource, BaseRecordsTable, UpsertRecordsTable) Input Employees table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 6. Upsert Multiple Records With The Patch Function 17 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 ); 6. Upsert Multiple Records With The Patch Function 18 Output Employees table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Henderson 1001 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 false 5 Kelly Smith 1066 08/01/2022 true 7. Change Values In A Record Variable Using The Patch Function 19 7. Change Values In A Record Variable Using The Patch Function Syntax Patch(Record1, Record2) Input Record stored in a global variable named gblEmployee ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true Code Patch( gblEmployee, {EmployeeNumber: 1063} ); Output Employees table in SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1063 05/28/2010 true
Compartilhar