cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
khalidinio
Level: Powered On

Set current user as default value of Person or Group field

We are using O365. I have some list with some columns. One of the columns is of the type "Person or Group". I customized the detail form in PowerApps. The detail form is used for new, display and edit of list items. I would like to set the current user in this "Person or Group" field.

 

I found some posts on this forum where you need to create a new datasource "Office365Users". And then you need to set this as default value:

 

Office365Users.MyProfile()

 

 

But this is not working. When I create a new list item, I see the default value is set with the current user. But when I save the list item I got an validation error. Is there a solution to make this work?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Set current user as default value of Person or Group field

 

Hi @khalidinio,

 

Only using the Office 365 Users function MyProfile() will not work for saving data to the People or group field in SharePoint list.

 

The person or group field actually stores data as record, if you would like to save this record of the current user, then you may take a try with the method mentioned in the following article:

PowerApps Set SharePoint Person field to Current user

 

Record example:

 

{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
}

 Or you may follow the steps below:

1. Select the Person or group field, un-lock it,

2. Change the Default property of the Dropdown box as:

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"", 
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},Parent.Default)

 

3. Change the Update property of the DataCard as below:

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},DataCardValue10.Selected)

Here DataCardValue10 should be the Person or group dropdown control.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
16 REPLIES 16
Community Support Team
Community Support Team

Re: Set current user as default value of Person or Group field

 

Hi @khalidinio,

 

Only using the Office 365 Users function MyProfile() will not work for saving data to the People or group field in SharePoint list.

 

The person or group field actually stores data as record, if you would like to save this record of the current user, then you may take a try with the method mentioned in the following article:

PowerApps Set SharePoint Person field to Current user

 

Record example:

 

{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
}

 Or you may follow the steps below:

1. Select the Person or group field, un-lock it,

2. Change the Default property of the Dropdown box as:

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"", 
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},Parent.Default)

 

3. Change the Update property of the DataCard as below:

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},DataCardValue10.Selected)

Here DataCardValue10 should be the Person or group dropdown control.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Re: Set current user as default value of Person or Group field

I:0# is it static ? Or changes between environments?
Beilul
Level: Powered On

Re: Set current user as default value of Person or Group field

@v-micsh-msft does it make any difference that I am trying this solution in a List form ? I tried it but It's not working. Do you have any idea why that might be?

Brice235i
Level 8

Re: Set current user as default value of Person or Group field

Not working for me either.

Brice235i
Level 8

Re: Set current user as default value of Person or Group field

Hi there, thank you for updating this code, but it still doesn't work.  

 

1. Select the Person or group field, un-lock it,

2. Change the Default property of the Dropdown box as:

no this didn't work for me.  I put this code instead on the DefaultSelectedItems attribute of the datacardvalue and it worked.  It did not work on the Default attribute.

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"", 
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},Parent.Default)

 

3. Change the Update property of the DataCard as below:

updated without error

 

If(Text(EditForm1.Mode)="1",{ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
},DataCardValue10.Selected)

Here DataCardValue10 should be the Person or group dropdown control.

 

However unfortunately though the current user is populated in edit mode, I save and play the app and the submitter field remains blank (current user is not displaying).

Community Support Team
Community Support Team

Re: Set current user as default value of Person or Group field

Hi @Brice235i,

 

Thanks for the testing.

 

So here the Person or group field allows multiple Values?

 

The formula I provided is only available for the Single value field, for Multiple value enabled field, the update property should be written as below:

If(Text(EditForm1.Mode)="1",Table({ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"",  
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
})
,DataCardValue10.SelectedItems)

Also the DefaultSelectedItems should be updated with, and you are right, the Default property will not work in such situation.

Thanks for the reminding:

 

If(Text(EditForm1.Mode)="1",Table({ 
  DisplayName:User().FullName,
  Claims:"i:0#.f|membership|" & Lower(User().Email), 
  Department:"", 
  Email:User().Email, 
  JobTitle:"", 
  Picture:""
}),Parent.Default)

See the reference:

ComboBoxDefault.gif

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Brice235i
Level 8

Re: Set current user as default value of Person or Group field

No, single value is fine.  It just isn't working.  It works in edit mode and in preview but when I play the app, the fields are blank.

Brice235i
Level 8

Re: Set current user as default value of Person or Group field

Hi the method presented in this post does not work for me in SharePoint online. @v-micsh-msft

 

This method does:

https://powerusers.microsoft.com/t5/General-Discussion/PowerApps-People-picker-Current-User/td-p/899...

 

In summary:

Welcome Page

OnStart

Set(gvCurrentUser, Office365Users.MyProfileV2());

Set(gvCurrentManager, Office365Users.ManagerV2(gvCurrentUser.userPrincipalName))

 

 

EditScreen

Current user datacard value

DefaultSelectedItems

//Default formula for the data card value

If(EditForm1.Mode = FormMode.New,

{

DisplayName: gvCurrentUser.displayName,

Claims: "i:0#.f|membership|" & gvCurrentUser.userPrincipalName

},

Parent.Default

)

 

OnChange

Set(gvCurrentManager, Office365Users.ManagerV2(DataCardValue35.Selected.Email))

 

Current user datacard

DataCardValue35.Selected

 

Manager datacard value

Default SelectedItems

//Default formula for the data card value

If(EditForm1.Mode = FormMode.New && Not( gvCurrentManager.userPrincipalName = ""),

{

DisplayName: gvCurrentManager.displayName,

Claims: "i:0#.f|membership|" & gvCurrentManager.userPrincipalName

},

Parent.Default

)

 

 

Manager datacard

DataCardValue17.Selected

 

Madi
Level: Powered On

Re: Set current user as default value of Person or Group field

have u found solution for this because iam also getting field blank 

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 388 members 4,770 guests
Please welcome our newest community members: