Canvas Apps Error Management SharePoint

How to default a SharePoint person column

Picking a person from a list
Picking a person from a list

Introduction

I promise I will go back to my series on responsiveness. But if I don't write about an issue or question when someone asks me, I tend to forget about it. I definitely don't want that to happen. Especially with this question about defaulting person column in a SharePoint list when creating a record through a canvas app.

SharePoint List Setup

The SharePoint list we will use is a very simple one. I added one new column called Person Lookup and set the type to Person or Group.

This is how the site settings look like:

SharePoint List Settings
SharePoint List Settings

And this is how a standard SharePoint form looks like for this list:

New record form
New record form

Canvas App Setup

Following these steps to follow along:

  1. Create a canvas app from blank
  2. Add the SharePoint you created above as a data source to your app
  3. Add an Edit form and connect it to the list
  4. Set the form Default Mode to New

It should look like this:

Edit Form with no changes
Edit Form with no changes

Problem with Person column

Select the combo box for the person lookup column and go to the Advanced properties tab. Select 'Unlock to change properties'. Notice that its Items property is set to:

Choices([@'People List'].PersonLookup)

To learn more about the Choices function, click here.

There are two problems here. First is that the Items property uses the Choices function. Which means that it will display a list of all unique person values from the list. The problem is that the list is empty. And so, this combo box is empty. I will talk about the 2nd one below.

Defaulting a Person column

Suppose you want to default the combo box to, say, your manager. To do that, you would follow these steps:

  1. Add Office365Users connector as a data source in your app
  2. Capture your own user profile in a variable
    Set(gblUser, Office365Users.MyProfileV2().userPrincipalName)
  3. Next set the DefaultSelectedItems property of the combo box to:
    Office365Users.ManagerV2(gblUser)

As you can see, the combo box is still blank and does not default to anything.

Changes to Person column combo box

Implement the following set of changes to make all of this work.

  1. We will rely on Office365Users to populate and default the combo box. Set the Items property of the combo box to:
    Office365Users.SearchUser({searchTerm:Self.SearchText, top:999})
  2. Set its DefaultSelectedItems property to:
    [Office365Users.ManagerV2(gblUser).displayName]
  3. If you have a manager set up, the combo box should now default to your manager.
  4. If you try to submit the form as is, the submit will work but if you look at your list, you will see that the Person Lookup column is blank.
  5. To fix this, change the Update property of the Person Lookup column's data card (DataCardValue5 is my combo box for Person Lookup) from
    DataCardValue5.Selected

    to

    { 
      Claims: "i:0#.f|membership|" & Lower(DataCardValue2.Selected.Mail),
      DisplayName: DataCardValue2.Selected.DisplayName,
      Email: DataCardValue2.Selected.Mail,
      Department: "",
      JobTitle: "", 
      Picture: ""
    }
  6. Submit and verify that the record gets created properly.
  7. If you don't have a manager set up, your combo box will look like this:

    When a user does not have a manager
    When a user does not have a manager
  8. To fix this, set the "Formula-level error management" preview app setting to true (should be true by default in most cases) and change the DefaultSelectedItems of the combo box to:
    If(
        !IsError(Office365Users.ManagerV2(gblUser).displayName),
        [Office365Users.ManagerV2(gblUser).displayName]
    )
  9. PRO TIP: If your combo box doesn't default to any record, check if your O365 profile has a manager or not. To test that quickly, add a label and set its Text property to:
    Office365Users.ManagerV2(User().Email).displayName

Congratulations, you now have a combo box for a person column in a SharePoint list that you can default to a certain user!

Recent articles

  1. Know if a user is using Desktop or Mobile/
  2. How to fix - Error when trying to retrieve data from the network
  3. Lookup users the right way in Power Apps!

Leave a Reply