Managing Variables in Custom SharePoint Forms via Power Apps
Image Source: Shutterstock.com
Power Apps
Sep 27, 2023 3:31 PM

Managing Variables in Custom SharePoint Forms via Power Apps

by HubSite 365 about Michel Mendes [MVP]

Microsoft MVP | Senior Consultant at Avanade | Microsoft 365 | Power Platform | SharePoint

Citizen DeveloperPower AppsSharePoint OnlineM365 Hot News

Master handling variables in SharePoint custom forms with Power Apps for optimized form customization!

Creating Custom Forms for SharePoint with Power Apps: Handling Variables and Understanding Form Behaviour

Author Michel Mendes [MVP] clarifies the process of crafting custom forms for SharePoint lists or libraries using Power Apps. This is achievable directly from the list command bar through the Integrate/Customise the Form option. By using this option, a completely new custom form featuring all Canvas app elements can be created whilst retaining the inherent SharePoint list view attributes such as filtering, sorting, grouping, and JSON formatting.

It allows for a more sophisticated form to be swiftly constructed using the Canvas apps studio. Nevertheless, it's crucial to consider how integration with Power FX and Canvas application features influence form variables. The Screen.OnVisible event adds some complexity as it only activates when an item in a list or view is opened for the first time, or if multiple screens are created and navigated to it.

If another item in the view is selected, the Screen.OnVisible event will not be triggered automatically. Consequently, for individuals accustomed to working with Canvas apps, this behaviour can be puzzling, potentially leading to confusion, misinterpretation, and bugs in the form.

Mendes advises that although context variables can be used, they may not be particularly useful for managing data related to specific items or open form instances. He exemplifies this with a multi-tab form, where context variables would not efficiently store the value of a selected tab.

He then instructs on how to circumvent such behaviour. In every SharePoint list custom form built with this platform, integration events are launched when interacting with the item and the form is opened or closed. These events can be located and Power Fx formulas added to them in the SharePoint integration object to overcome the challenge.

Five events are available: OnNew, which triggers when creating a new item; OnEdit when editing an existing item; OnView when viewing an item; OnSave when clicking the save button, and OnCancel when pressing the cancel button. By using these events, global variables in the application can be manipulated and essentially reset if necessary. Therefore, when loading another item from the list, the data retrieved from the variable values will be accurate.

Finally, he points out that the events are initiated solely from the Power Apps form. Therefore, quick edit views will not trigger these events. However, through these SharePoint integration events, variables in a custom form can be appropriately managed. Mendes' explanation is a helpful resource for understanding the mechanism of SharePoint custom forms better. More on this can be found in this guide.

Understanding SharePoint Custom Forms in General

SharePoint custom forms are a powerful tool allowing users to tailor their data input experiences to suit their needs. By harnessing the potential of Power Apps, users can unlock the full functionality of custom forms, creating unique applications for data gathering, interaction and analysis. Variables and events are core components that need to be managed appropriately, but once mastered, they provide the user with an unparalleled level of control and customization.

Read the full article Handling variables in SharePoint custom forms built with Power Apps

Power Apps - Managing Variables in Custom SharePoint Forms via Power Apps

Learn about Handling variables in SharePoint custom forms built with Power Apps

In the realm of SharePoint custom forms creation, Microsoft Power Apps is a powerful tool that enables you to craft bespoke forms directly from the list command bar under the Integrate/Power Apps/Customize Form option. This extends the possibility of incorporating a wide array of features provided by Canvas Apps.

For more intuitive SharePoint list viewing, you may utilize Power Apps' native features like sorting, filtering, grouping, and JSON formatting, coupled with the Canvas apps studio, to engineer a brand-new form from scratch.

Despite the flexibility in form customization, understanding how variables operate in Power Apps is of chief importance. It can cause confusion for those familiar with Canvas apps as the event Screen.OnVisible is only set to be activated during the first instance of opening an item in a list/view or when you devise multiple screens and navigate to it. Furthermore, the utilization of context variables might not be sufficient if you aim to control data related to distinctive items or current form instances. For instance, if you're managing a form with several tabs and wish to store the chosen tab value in a variable, relying on context variables might not serve your purpose.

Power Apps addresses this limitation with its integration events feature, especially when interacting with an item and during the form's opening or closure procedures. Through the SharePoint integration object, you can discover these events and further introduce Power Fx formulas to them.

In total, there are five available events:

  • OnNew: Initiates when the form opens to create a new item
  • OnEdit: Activates when the form opens to edit an existing item
  • OnView: Triggers when the form opens to view an existing item
  • OnSave: Starts when the save button is engaged
  • OnCancel: Begins when the cancel button is clicked

Power Apps allows for the usage and resetting of global variables in your app during these events, providing the assurance of correct variable values, even if another item from the list is loaded. It's vital to remember that these events are solely set off from the Power Apps form and don't trigger when in quick edit view scenario.

With the implementation of SharePoint integration events, you can effectively control variables in a custom form. This enables a more streamlined experience in creating and managing customized SharePoint list forms.

How does customization of SharePoint list form sound? Dive into this MS Learn guide for an in-depth understanding.

For a comprehensive guide about managing variables with SharePoint custom forms using Power Apps, visit this post that initially appeared here.

More links on about Handling variables in SharePoint custom forms built with Power Apps

Handling variables in SharePoint custom forms built with ...
Feb 19, 2023 — Handling variables in SharePoint custom forms built with Power Apps · OnNew: triggers when the form is open to create a new item · OnEdit: ...
Handling variables in SharePoint custom forms built with ...
Handling variables in SharePoint custom forms built with Power Apps is the process of storing data temporarily during a form session. Variables can be used to ...
Create a variable in PowerApps to custom a SharePoint List?
Jan 16, 2021 — One small change, I would put the UpdateContext({varFlag:"N"}) in the OnSuccess property of the form. I don't think that you want it to change ...

Keywords

SharePoint Custom Forms, Power Apps, Handling Variables, Power Apps SharePoint, SharePoint Power Apps Integration, Custom Forms in SharePoint, Power Apps Forms Creation, Variable Handling in Power Apps, Building SharePoint Forms, Power Apps for SharePoint.