Learn DYNAMICS-POWER-PLATFORM with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Simple Canvas App Counter
Set(varCounter, 0);
// Button OnSelect
Set(varCounter, varCounter + 1);
UpdateContext({displayCounter: varCounter})
// Label Text
Text = displayCounter
Increment a counter and display it on a Canvas App screen using a button.
2
Patch Record to Dataverse Table
Patch(Accounts, LookUp(Accounts, AccountName="Contoso"), {Revenue: 1000000, Status: "Active"});
Update a specific record in a Dataverse table using the Patch function.
3
Filter Gallery by Text Input
Filter(Contacts, StartsWith(FullName, TextInput_Search.Text))
Filter a gallery dynamically based on user input in a TextInput control.
4
Send Email Using Power Automate Flow
PowerAutomateFlow.Run({To: "user@example.com", Subject: "Hello", Body: "Automated email from Power Platform."});
Trigger a flow to send an email when a button is clicked in Canvas App.
5
Create Record in Dataverse
Patch(Accounts, Defaults(Accounts), {AccountName: "New Account", Revenue: 50000, Status: "Prospect"});
Add a new account record to a Dataverse table using Patch.
6
Update Multiple Records
ForAll(Filter(Accounts, Status="Prospect"), Patch(Accounts, ThisRecord, {Status: "Active"}));
Update all accounts with a specific status.
7
Conditional Visibility of Controls
Button.Visible = Toggle_Show.Value
Show or hide a button based on a toggle switch.
8
Compute Total from Gallery Items
Sum(Gallery1.AllItems, Quantity * Price)
Sum a numeric column from a gallery's datasource.
9
Trigger Approval Flow
ApprovalFlow.Run({Requester: User().Email, Amount: TextInput_Amount.Text, Description: TextInput_Desc.Text});
Invoke an approval process using Power Automate flow from a Canvas App.
10
Patch with Lookup Value
Patch(Contacts, LookUp(Contacts, FullName="Alice"), {ParentAccount: LookUp(Accounts, AccountName="Contoso")});
Update a record with a lookup field value in Dataverse.