Today, we will delve into some practical tips and tricks that can enhance your experience while working with Power Apps. Whether you’re a seasoned developer or just starting out, these tips will help you streamline your workflow and make the most out of the Power Platform.
In this post, we’ll cover various aspects of working with Dataverse forms in canvas apps, including how to handle different form modes, retrieve the last submitted data, and reset variables in SharePoint-integrated Power Apps. Additionally, we’ll explore how to use the concurrent function to load multiple data sources quickly, get current user details, and cache data for better performance.
Form modes
When working with a Dataverse form in a canvas app, you sometimes need different behavior for the edit, new, or view mode of the form. Each mode is represented by a number, and you can use the following code to check the current FormMode. Form2 is the name of the form.
If(Form2.Mode = 0, "Edit", Form2.Mode = 2, "View", "New")
Enum Name | Numeric Value |
---|---|
FormMode.Edit | 0 |
FormMode.New | 1 |
FormMode.View | 2 |
It can also be done by comparing the Mode of the form SharePointForm1.LastSubmit.ID with the FormMode.Edit / View or New code.
If(Form2.Mode = FormMode.Edit, "Edit", Form2.Mode = FormMode.View, "View", "New")
Last submitted data
When working with a form to submit data to Dataverse you can get the last submitted data. You can get the ID of the created record by calling the LastSubmit followed by the name of the ID column.
Form1.LastSubmit.Contact
This can also be done with a SharePoint integration power app by calling the LastSubmit code from the SharePoint form.
SharePointForm1.LastSubmit.ID
Reset variables in SharePoint integrated Power App
When you set variables in a SharePoint integrated Power App don’t forget to reset them when the user closes the app either resetting the variables in the OnCancel or OnSave or resetting them when the form gets opened.
Set(varStatus, Blank());
Set(varFlag, false);
Use concurrent to load multiple sources quicker
When you want to store multiple sources locally, you can load them in a collect one after the other.
ClearCollect(Account, Accounts);
ClearCollect(Contact, Contacts);
But you can also load them in parallel by using the concurrent function. This will load them faster by loading them at the same time.
Concurrent(
ClearCollect(colAccount, Accounts),
ClearCollect(colContact, Contacts)
);
Get current users details
You can get the current user’s details by using the User() function.
User().EntraObjectId;
User().Email;
User().FullName;
User().Image;
Cache data that does not change but is used in multiple locations
When you are calling the same function again to access a resource to get the same data it is better (faster) to retrieve it once and store it in a variable.
Set(varCurrentUserName
Set(varUsername, User().FullName);
Set(varMyAccountName, LookUp(Accounts, 'Account Name' = "Contoso, Ltd."));
Drop-down not showing the correct values
Sometimes when you add a drop-down to a canvas app the displayed values are item 1, item 2 etc. Instead of the actual values. This happens when the drop-down list options are not loaded correctly.
Go to the DisplayFields property of the drop-down and set the it to [“Value2”] instead of [“Value”]. The canvas app will see that this is incorrect and change it back to [“Value”] and refresh the drop-down values. Now all the correct values will be visible.