Understand SharePoint forms integration
You can customize a form for a SharePoint list when you integrate a list into Power Apps. In this article, you see how these forms work and how you can customize them.
When you customize a form for a list, you see the default generated form works for all operations, like creating, showing, or editing an item. This functionality uses generated formulas and the SharePointIntegration control.
Note
When you create or view a list in SharePoint, you're automatically redirected to Microsoft Lists. The list can always be found in both Microsoft Lists and SharePoint. Learn more in What is a list in Microsoft 365?
Understand the default generated form
The default generated form consists of the following controls and their corresponding defaults. Formulas are autogenerated within the defaults.
FormScreen1: This screen contains the form.
SharePointForm1: This form can create, show, or edit a list item.
Data Source: The list for which the form is customized. For example, a SharePoint list acts as a data source.
Item: A selected item from a list. This item is set to
First()
item in the list for your convenience, when working in Power Apps Studio.If( IsBlank(SharePointIntegration.Selected) || IsEmpty(SharePointIntegration.Selected), First('*YourListName*'), SharePointIntegration.Selected )
Tip
This formula pattern uses
... SharePointDatasourceName.Selected
and works for the Item property of a form. See the Common issues with the SharePointIntegration object for a formula pattern to set the value of a SharePoint record.
OnSuccess: Once the item is created or saved successfully, the form is reset and SharePoint hides the form.
ResetForm(SharePointForm1); RequestHide()
SharePointIntegration: Communicates user actions between SharePoint and Power Apps.
Property Description Example Data Source The list for which the form is customized. YourListName OnNew Sets SharePointForm1 in new mode. NewForm(SharePointForm1) OnView Sets SharePointForm1 in view mode. ViewForm(SharePointForm1) OnEdit Sets SharePointForm1 in edit mode. EditForm(SharePointForm1) OnSave Submits the changes to SharePointForm1. The SharePointForm1.OnSuccess formula executes when you successfully submit a form. SubmitForm(SharePointForm1) OnCancel Resets the changes to SharePointForm1. SharePoint always hides the form when a user selects Cancel in SharePoint. ResetForm(SharePointForm1)
These defaults ensure that the form works when running within SharePoint. The defaults change the Power Apps form mode as the user interacts with it in SharePoint, and they ensure that the changes are submitted to SharePoint.
Understand the SharePointIntegration control
The SharePointIntegration control communicates user actions between SharePoint and Power Apps.
Note
You can access properties for the SharePointIntegration control only when the form is running in SharePoint, not when you're customizing the form in Power Apps Studio. These properties might not be available in OnStart or OnVisible.
The SharePointIntegration control has these properties:
Property | Effect or description |
---|---|
Selected | The selected item from the list. |
OnNew | Activates when a user selects the New button or opens the Create item form in SharePoint. |
OnView | Activates when a user selects an item or opens the Item detail form in SharePoint. |
OnEdit | Activates when a user selects the Edit all button or opens the Edit item form in SharePoint. |
OnSave | Activates when a user selects the Save button in SharePoint. |
OnCancel | Activates when a user selects the Cancel button in SharePoint. |
SelectedListItemID | Item ID for the selected item in a list. |
Data Source | The list that contains the record that the form shows, edits, or creates. If you change this property, the Selected and SelectedItemID properties might stop working. |
Customize the default form
You can change the formulas to further customize the forms.
Consider these tactics when you customize forms:
Use the OnSave formula of the
SharePointIntegration
control to customize the effect of a user selecting Save in SharePoint. If you have multiple forms, make sure to submit the changes only for the form currently being used.Tip
Set different values for a variable in the OnNew, OnView, and OnEdit formulas. You can use this variable in the OnSave formula to determine which form is being used.
Include RequestHide() in the OnSuccess formula of all your forms. Without this function, SharePoint doesn't know when to hide the form. Avoid running important code after calling RequestHide(). Code should run while the form is still visible and able to run logic.
You can't control the hiding of a form when a user selects Cancel in SharePoint. Always reset your forms in the OnCancel formula of the
SharePointIntegration
control.Properties for the
SharePointIntegration
control might not be available in OnStart or OnVisible. These events execute only once while the list is loaded. You can use OnNew, OnView, or OnEdit to run logic before the form is shown to the user.
Common issues with the SharePointIntegration object
When the value of
SharepointIntegration.Selected
is set to a collection on the OnView property, it doesn't show the latest value. The recommended way to fix this problem is to useSharepointIntegration.SelectedListItemID
, and then do a lookup on the table to get the selectedRecord.For example, for OnView property:
Instead of:
Set( selectedItem, SharePointIntegration.Selected );
Use:
Set( selectedLookupItem, LookUp( YourSharepointIntegrationObject, ID=SharePointIntegration.SelectedListItemID ) );
Collection variables aren't reset on closing the Power Apps form and the state is persisted for the entire session. If there are any use-cases where the variables need to be reset, clear the variables in the OnView property of the
SharePointIntegration
object.Don't use imperative functions such as Launch() in the
SharePointIntegration
properties (such as OnNew and OnView). This use can cause unexpected behavior since theSharePointIntegration
lifecycle events (such as selections changing) can trigger in the background even when the form isn't visible.