Multiple SharePoint list forms on 1 Power Apps custom form

In Power Apps it is possible to have multiple SharePoint list forms on one list’s custom form.

The SharePoint setup

I created two SharePoint lists. With a lot of imagination I called them list 1 and list 2.

When I create a new item in list 1 I want to create an new item in both lists. When I edit an item in list 1 I want to edit the items in both lists.

If you want to use this pattern in a normal canvas app that isn’t a custom form then just add the forms as described in the Microsoft documentation about forms in Power Apps.

Multiple SharePoint list form

Using the Power apps menu option on list 1, I created a custom form with Power Apps that looks like this.

Multiple SharePoint list form
Multiple SharePoint list form

The Orange form is the one that writes to list 1 and the green form writes to list 2. The first form is added by Power apps, the second one I had to add to the same screen. With a bit of resizing of the app it isn’t too difficult to do.

Now when I set the title of both forms to item 1 and hit the save button …

Multiple SharePoint list forms on 1 Power Apps  custom form 1

Only the item in the first form is saved to list 1. List 2 is not updated. So even though I have Multiple SharePoint list form only one of them is really used.

My second form is also not reset back to empty values. We will need to do some work here to make it all work as expected. Multiple SharePoint list forms may not be that easy.

Updating multiple datasources

First of all you could consider other data update methods as I described in Patch, SubmitForm and Update. However this time I will just use the Submitform and other form operations.

First of all we need to have a look at a number of pieces of code in the form that will need to be updated.

Multiple SharePoint list forms on 1 Power Apps  custom form 2

The code that we need to consider is:

  • OnCancel
  • OnEdit
  • OnNew
  • OnSave
  • OnView

OnSave

The OnSave is by default set to:

SubmitForm(SharePointForm1)

To make sure that the item is saved to the second item I will need to update the onSave to support my additional form. This second form is called Form1

SubmitForm(SharePointForm1);
SubmitForm(Form1)

With this OnSave code the out of the box save button.

OnEdit

The OnEdit is set to

EditForm(SharePointForm1)

You might think that the following code would work, but …

EditForm(SharePointForm1); 
EditForm(Form1)

… you will find only one item is being edited.

Multiple SharePoint list forms on 1 Power Apps  custom form 3

So I added the the Item for my green form

First(Filter(List2, Title = DataCardValue1.Text))
Set item to support Onedit

And now when I edit an item I get both items to appear. Ok, this example isn’t very exciting and quite often you might have to use different fields to link the items in the separate lists.

Just make sure that you have a key field that you can match up in both lists.

Also as the lists may contain more items , you might need to consider setting your indexes on the list columns correctly as multiple SharePoint list forms will hit both lists.

Multiple SharePoint list forms on 1 Power Apps  custom form 4

But hey, we now have something that look like a relational Power app form!

OnCancel

The OnCancel is set to

ResetForm(SharePointForm1)

This will need to be updated to

ResetForm(SharePointForm1); 
ResetForm(Form1)

OnNew

The OnEdit is set to

NewForm(SharePointForm1)

This will need to be updated to

NewForm(SharePointForm1); 
NewForm(Form1)

OnView

The OnView is set to

ViewForm(SharePointForm1)

This will need to be updated to

ViewForm(SharePointForm1); 
ViewForm(Form1)

Further Thoughts

When merging two lists into one I might consider most of the time to create a screen with many controls on it and then use the patch function instead of the forms.

However as a quick solution I could consider the multiple SharePoint list form approach as described in this post.

It doesn’t suit all use cases but definitely some.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: