PowerApps – Office 365 Group Filtered People Picker

powerapps-office-365-people-picker

In several situations there is a requirement to produce a people picker that stores information in a SharePoint list, but is filtered by Office 365 groups. Given a ‘SharePoint list People field’ can only be filtered by a SharePoint group, leveraging the Office365Groups connector makes achieving this goal simpler.

There is one major issue with using the Office365Groups connector, which is that the object returned by it is different to that which SharePoint uses.

Example PowerApp

For our example PowerApp, we will be working with a “Clients” list containing a title for the client name and a manger people picker field to store the client’s manager.

Adding these fields into a PowerApps form we get the following setup:

powerapp_form

To get the form working in a simple way, we set the form’s Item property to be either “Defaults” or the last submitted item:

default_submitted

Our Save button just submits the form:

submit_form

And the reset button clears it:

reset_form

By default, the Manager field is populated with all SharePoint users.

To change this to use the Office365Groups connector we need to make the following changes:

Select the combo box and edit the “Fields” property to be “Double” instead of “Person”

office365_connectors

This must be done as the Office365Groups connector doesn’t provide image functionality, meaning the Person layout will not render properly.

Next, using the Data tab, add the Office365Groups connector:

data

With the connector now created, the Items property of the combo box needs updating. This needs to be updated to use the Office365Groups ListGroupMember’s function. The GUID parameter that is passed to this function comes from your Azure Active Directory’s group’s Object Id property.

This can usually be found by navigating to your Azure environment and loading up the Azure Active Directory blade: https://portal.azure.com/#blade/Microsoft_AAD_IAM/GroupsManagementMenuBlade/AllGroups

Find the group you require and copy the Object Id.

Once you have this, updating the Items property can be done using the following function:

update_function

The list of members is contained within the value property returned from the function.

This should, but might not, automatically update the display fields and search fields of the combo box. These should be updated to the following:

display_namemail
display_name

With these updates made, the combo box will now display the list of users returned by the Office365Groups connector.

However, you will find that saving and loading the user back up again does not work. This is the trouble with SharePoint using different user types than the connector.

To overcome this issue, the following changes need to be made to the DataCard’s properties.

To get saving to work, the update property of the DataCard needs to be updated to transform the object in the combo box to that which SharePoint can use:

update_datacard

This update checks to see if a user has been selected, if it has not been then a blank object is returned. If a user has been selected, then an object is returned in a format that SharePoint can use.

If, at this point, you populate your form and click the save button, you will find that your SharePoint list has been updated with the correct user. But your form does not load it up again. This is resolved by updating the “Default” property of the DataCard:

lookup-groupmembers

This will perform a lookup on the list of group members, filtering down to the loaded user’s email address.

When this update has been made, you will find the user is now loaded correctly into your form.