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?
Solved! Go to Solution.
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
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
@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?
Not working for me either.
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:
Regards,
Michael
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.
Hi the method presented in this post does not work for me in SharePoint online. @v-micsh-msft
This method does:
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
User | Count |
---|---|
124 | |
87 | |
87 | |
75 | |
69 |
User | Count |
---|---|
215 | |
181 | |
140 | |
97 | |
83 |