cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
khalidinio
Frequent Visitor

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
v-micsh-msft
Community Support
Community Support

 

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.

View solution in original post

19 REPLIES 19
v-micsh-msft
Community Support
Community Support

 

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

I:0# is it static ? Or changes between environments?

@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
Impactful Individual
Impactful Individual

Not working for me either.

Brice235i
Impactful Individual
Impactful Individual

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).

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.

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
Impactful Individual
Impactful Individual

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

 

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

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,217)