cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DeannaT
New Member

How to Default a People Picker to current user & save to SharePoint List source

Hi,

 

I am trying to create a very simple PowerApp based on a SharePoint list.  This list has a Person field.  When I initially create the PowerApp, if the user types in a person's name and chooses one, it saves fine.  As soon as I try to default the Person field in the PowerApp to "current user" (using any of the User(). syntax options), my PowerApp stops saving back to the SharePoint source list. 

 

Any ideas?

48 REPLIES 48
Lisa_T
Frequent Visitor

Thank you! this is exactly what I needed.

In here what is this SalesPerson_DD (in red text color)?

 

If( Account_Detail_Edit_Display_Long_1.Mode = FormMode.New,
         {
             '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
              Claims:"i:0#.f|membership|" & Lower(User().Email),
              Department:"",
              DisplayName:User().Email,
              Email:User().Email,
              JobTitle:"",
               Picture:""
         }, SalesPerson_DD.Selected)

Evelyn-Jiang
Frequent Visitor

I am looking for the Same. Is there any updates now?

RebeccaS (somewhere in this thread) helped me - I'm copying it below: 

If I want the data card to default to the current user I set a variable at the start that is = Set(_CurrentUser, User())

Then on the combo box I put as the DefaultSelectedItems: {DisplayName: _CurrentUser.FullName}
^ this does nothing but show the name so if you are hiding it then it is no necessary

Then on the cards Update value I put :

If(ComboBox.Selected.DisplayName=_CurrentUser.FullName,
{DisplayName: _CurrentUser.FullName,
Claims:"i:0#.f|membership|" & Lower(_CurrentUser.Email),
Department:"",
Email: _CurrentUser.Email,
JobTitle:"",
Picture:""}, ComboBox.Selected)

This is basically saying to default to the current user but if they change it then take that instead. I have seen several people say "easier" ways of doing it but I have been using this for a while and it works great...the other ways I have seen I have had trouble with them. This works 100% of the time for me.

From <https://powerusers.microsoft.com/t5/Building-Power-Apps/How-to-Default-a-People-Picker-to-current-us...>

If(DataCardValue2.Selected.DisplayName = strCurrentUser.FullName,{DisplayName: strCurrentUser.FullName, Claims:"i:0#.f|membership|" & Lower(strCurrentUser.Email),
Department:"",
Email: strCurrentUser.Email,
JobTitle:"",
Picture:""}, DataCardValue2.Selected)

I would just change the line of DisplayName: User().Email to DisplayName: User().FullName.

BrokenClock
Helper I
Helper I

For people still viewing this thread, unless I'm misunderstanding how the sharepoint people backend works, you actually only need the claims field to be populated, as sharepoint will automagically derive all the other properties from it.
This means (according to my quick tests) the only line you need is

{Claims:"i:0#.f|membership|" & Lower(_CurrentUser.Email)}

 Or, if you don't want to use a variable to store the current user (I wonder what the performance implications are with this, if any)

{Claims:"i:0#.f|membership|" & Lower(User().Email)}

If you need to populate a People column in SharePoint using a Power Automate flow, you're right: Claims (user's e-mail) is all you need. But when it comes to populating this column using a Power Apps app, it doesn't work because Power Apps identifies the register schema to save values to this column. When you add only Claims in a Patch, for example, red lines indicates you have an error and this error says the data source need a Record value, but with a different schema.

 

Sem título.png

 

 

 

 

 

 

 

 

(translation of the image above, something like: "Invalid argument type. Waiting for a Record, but with a different schema. Missing column. Your formula has a missing column 'Department' with 'Text' type. Patch function has some invalid arguments")

 

So, reforcing some of the right answers to this question, the right schema is: 

 

{ 
  '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", 
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"", 
  DisplayName:User().FullName, 
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
}

 

While the patch function may fail without extra content, the Update function of a Data Card in a form seems to be just fine with just the claims.

BrokenClock_0-1659529616672.png

I wonder, would the patch function work with empty values for every column, except claims ?

You're right, it works in Update property of the DataCard. 

I also tested Patch function leaving all properties but Claims as blank values and it worked. So, you're right again. Claims is all you need, but using Patch function, the schema must be respected, even if you leave all other properties blank.

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (1,332)