As you probably know, it’s very easy to customize the standard SharePoint form for a list or library using Power Apps. However, if you’re working with document sets it’s not as easy. Well, it’s just as easy to create the custom form. What’s currently not possible out of the box is to choose any document set content type using the content type field of the SharePoint form. In this post I share a solution using Power Automate that does allow you to create a document set from a Power Apps customized SharePoint form without using any code.
💡 We start with a document library in SharePoint that has a document set content type already added to it.
Solution: Power Automate
Create a new Instant flow in the default environment of your tenant. It has to be in the default environment since otherwise you won’t be able to add it into the customized form later on. Choose Power Apps as the trigger for the flow.
Add an Initialize variable action for all metadata that you need to create the document set. In my case that’s Name , Description, Status, Deadline and Size. Make sure to choose an appropriate type for the types of variables that you’re working with.
💡 I’m renaming my actions to the name of the variable so the input variables have a clear name when adding the flow to my canvas app later on.
Add Ask in PowerApps as dynamic content in each of the variables you’ve created so that they become input parameters for your flow.
The next steps is where the magic happens. I always think of document sets as “folders with metadata” and introduce them to customers as such. Also, if you sync libraries that have document sets in them using OneDrive sync, document sets show up as folders in your file explorer. This lead me to conclude that you can create a document set using two steps:
- Create a folder in the library
- Change the content type of the created folder to that of the document set
To create a folder, add the Create new folder action to your flow. Fill in the parameters for the library and choose the Name variable as folder name. Next, add an Update file properties action. Fill in the library parameters and in the Id, add the Id of the folder that was created in the previous step.
Now you’ll notice that the document set content type is not available in the Content type Id dropdown. To change the content type to that of the document set, we need to get the Id from SharePoint and add it as a custom value into the Update file properties action. To get the content type Id, open the library settings in SharePoint and select the document set content type (to do this, “allow management of content types” needs to be turned on). When you have the library content type open, the content type Id will be at the end of the url after “&ctype=” (indicated in yellow in the below image). Copy everything after the equals sign and paste that into the Content type Id field as a custom value.
Now you can add the other variables as inputs for the corresponding metadata fields. Finally, save the flow. The resulting flow should look similar to the below image. Now we can customize the SharePoint form.
Solution: Power Apps
Open the document library for which you want to customize the form. Then choose Customize forms from the Power Apps dropdown in the menu bar. Power Apps will initialize your form with only the Title field present (which we actually don’t need). Start by adding all other fields you want users to fill to the form, leave the Title field in there as well. We’ll customize it to show the Name field instead.
Unlock the Title data card from the advanced properties and add Name into the DataField property of the data card. Change the label text to Name.
Now we need to make sure that the form behaves correctly both when creating and when editing the properties of the document set. Therefore, we need to make 3 additional changes.
1. Change the “OnSave” property of the SharePointIntegration
In the OnSave property of the SharePointIntegration, we need to make sure that the creation flow is called when creating a new document set. Since I have not created an edit flow I want to simply submit the form when editing the document set properties. If you have created an edit flow, make sure to add it into the second part of the formula.
To add the flow into the form, temporarily add a button control to the app and add your flow using the Action menu. (It cannot be added directly into the OnSave property.) After the flow has been added, you can delete the button and add the following formula into the OnSave property of the SharePointIntegration control. (Note that the name of the form in the below formula will be different if you renamed it in the Power App)
If( SharePointForm1.Mode = FormMode.New, // FormMode.New: Run the flow and reset the form YourFlowName.Run(InputProperty1, InputProperty2, ...); ResetForm(SharePointForm1), // FormMode.Edit: Submit the form SubmitForm(SharePointForm1) )
In my case, the OnSave property looks as follows:
2. Change the OnReset property of the SharePoint form control to RequestHide().
3. Change the DisplayMode property of the Title/Name data card value
When submitting an edit form, the customized form does not make any changes to the Name of the document set. Therefore, to avoid confusion with users wanting to change the name of the document set, I want to make sure that in edit mode the Name data card is not editable.
Add the following formula into the Name text input control’s DisplayMode property:
Result & considerations
The customized form is ready to be used and will work both when creating a new document set and when editing the properties of an existing one.
An important drawback of this approach is that saving the form when creating a new document set will not trigger a refresh of the SharePoint page. Users will have to do a manual refresh to see their newly created document set. Depending on the number of actions in your flow before creating the document set, the creation might take some time and the document set will not immediately show up.
If you’re working with multiple document set content types, you have to resolve the guid of the selected content type in order to create a document set with the right one. In this case, I have hardcoded the content type guid into my flow. It’s also possible to get the guid using a SharePoint HTTP call and resolving the required one based on the name. However, this takes some additional manipulations and would have led too far for this blog post.