in Flow, SharePoint

Validate SharePoint Person field in Microsoft Flow

Dealing with person fields

Person fields in SharePoint are lookup columns. You can, of course, update person fields using Microsoft Flow. However, since its a lookup field, all it stores is the reference to that user, for example, something like this:

i:0#.f|membership|dougb@contoso.onmicrosoft.com

This then resolves to that user when its rendered by the people picker in SharePoint. As you can see, there is no check if the user is a valid user for that person field. For example, if you have configured the person field to only accept users from a specific SharePoint user group, you would want to ensure only that users get added to that column. Below, you can see I have configured my person column to accept users who are owners of the site.

settings-person-field

‘Resolve person’ flow action

If you are using flow, then you can use the following SharePoint action – Resolve person – to resolve a user for a particular person field, and then add/update the list items accordingly.

resolve-person-flow-action

Whether you are using the action to check for the right user or to just generate a proper user claims that you can use in SharePoint, the Resolve person action will help you with that.

Example flow using Resolve person action

Let us explore this using a simple scenario:

For documents in a document library, users can create a new project and also assign a Project Owner for a specific document that creates a new project item in a Projects list. 

As you might have guessed, the Project Owner field in the Projects list is a person field that accepts users who are owners of the site.

Below is my flow which runs on the selected item in a library:

complete-flow-resolve-person

The flow is configured with a custom input parameter that users will need to input when they execute the flow from SharePoint.

selected-item-action-input-parameter

The interesting part is using the Resolve person action:

resolve-person-flow-action

As you can see, the action takes the following input:

  • SharePoint site.
  • List name.
  • The person column against which you want to resolve the user.
  • Email or name of the user:
    • If you supply the name, it will work only if there is one match and fail if the result has multiple matches.
    • I prefer email as it is unique and works great!

The flow is then set up to create the new project item and send an email notification to the user who executed the flow whether the new project was created or not. Create new item action then uses the claims from the resolve person action output:

create-project-action

In my flow:

  • I have configured the email notification action immediately following the resolve person action to run only if the resolve person fails.
  • Only create the project item if the previous email notification action is skipped, which will be the case if the user was resolved properly.

Note: You can follow this pattern of handling failures in any flow and do the right thing. 

run-after-settings-flow-actions

Now when users execute the flow by selecting a document and entering a project owner, it will check and do the respective actions as described above!

execute-create-project-flow

An easy way indeed to resolve users properly before you create/update list items with person fields in SharePoint!

As always, let us know if you have any feedback! We are always listening!

 

Write a Comment

Comment