Introduction¶
Using this prompt is an efficient way to generate PowerFx formula:
You are an expert in Power FX formulas for Power Apps Canvas Design.
You assist by writing on demand formulas.
Please write a Patch function that ...
If you need more details, ask now, otherwise write the statement.
Patch snippets¶
// *** BULK CREATE ***
// Note that repeating call will fail as RequiredUniqueText must be unique
With({
data:[{ Title: "Sample A", RequiredUniqueText: "aaa2", StartDate: Date(RandBetween(2024,2026),RandBetween(1,12),RandBetween(1,31)) },
{ Title: "Sample B", RequiredUniqueText: "bbb2", StartDate: Date(RandBetween(2024,2026),RandBetween(1,12),RandBetween(1,31)) },
{ Title: "Sample C", RequiredUniqueText: "ccc2", StartDate: Date(RandBetween(2024,2026),RandBetween(1,12),RandBetween(1,31)) }]
},
Patch(
'Temp records',
ForAll(Sequence(CountRows(data)),Defaults('Temp records')),
data
)
)
// *** SIMPLE ONLY: UPDATEIF AND DELETEIF ***
RemoveIf('Temp records',true)
UpdateIf(
'Temp records',
true,
{ StartDate: DateAdd(StartDate, 1,TimeUnit.Days) }
)
// *** BULK UPDATE PATCH ***
ClearCollect(
colUpdates2,
Table(
'Temp records'@{ ID: 7, StartDate: DateValue("2025-01-02") },
'Temp records'@{ ID: 9, StartDate: DateValue("2025-01-02") }
)
);
Patch(
'Temp records',
ShowColumns(colUpdates2, ID),
colUpdates2
)
// *** BULK UPSERT PATCH ***
ClearCollect(
colUpdates2,
Table(
'Temp records'@{ ID: 7, StartDate: DateValue("2025-01-03") },
'Temp records'@{ ID: 9, StartDate: DateValue("2025-01-03") },
'Temp records'@{ ID: Blank(), StartDate: DateValue("2025-01-03"), RequiredUniqueText: GUID() }
)
);
Patch(
'Temp records',
ShowColumns(colUpdates2, ID),
colUpdates2
)
Remove delegation handling¶
fxRemoveSelectedItems(ok: Text, nok:Text):Text ={
// Remove of the found items is used instead of a RemoveIf construct to handle delegation limits.
// Only the most recent 500 items are considered as those are the only ones selectable anyway.
IfError(
With({tbl: ShowColumns(pcfDetailsList.SelectedItems,ID)},
Remove('List',Filter(FirstN(Sort([@'List'],ID,SortOrder.Descending),500) As tgt, !IsBlank( LookUp(tbl, ID = tgt.ID))))
),
nok,
ok
)
};
Reference¶
- 7 Ways To Use The PATCH Function In Power Apps (Cheat Sheet)
- Everything You Need To Know About Power Apps Patch Forms
- Patch forms give you total control over the design/layout of the form as opposed to Edit Forms which have a highly-defined structure
- Patch forms are easier to maintain since you can select all of the controls at once to change their style and re-positioning their input fields is drag-and-drop
- Patch forms can write their data back to a local collection which useful when a form has multiple screens or the app has an offline-mode
- Power Apps Patch Function Examples For Every SharePoint Column Type
- Power Apps Patch Function Error Handling - Matthew Devaney