I have Multi Select People column in PowerApps form. This People column is not editable by users. I wanted to set current logged in user claims when screen is loading (OnVisible) itself. No need set if that current user already in that column. Kindly let me know how to set the current user in Multi select people column.
Person A,
Person B,
Person C
If my column already loads with Person A and Person B come and open the PowerApps form, I have show like
People Column : Person A ; Person B
If Person C comes then Person A, Person B, Person C
Im not sure if this is what you are asking, but if you are trying to set a default on a person column then you would go about it with the following code.
{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:Concatenate("i:0#.f|membership|",User().Email),
DisplayName:First(Office365Users.SearchUser({searchTerm:User().Email})).DisplayName,
Email:User().Email
}
@Anonymous
If I am understanding you, you want to "grow" a multi-person column with new names as those new names access the screen in your app.
To do this, you need to check the current list and then append it with the current user if the user does not exist, but you must also put the original list of people back into the same column or they will all be replaced.
This can be done, but you have to convert the User() function results into a SharePoint user record (which @MatthewInwards has provided - @odata.type columns have not been needed for over a year now, so that is not used) and then you need to merge the existing table of people with the new record.
What you did not mention was any particular record in your list. You only mentioned a column, so I am not sure what record in your list you want to update. So for the purposes of this response, I will hard code an ID for a record. You will need to replace that logic with whatever you need to get the appropriate record.
So, here is the relatively generic formula for doing this:
With({_user: User(),
_peopleTable: LookUp(yourDataSource, ID=1, MultiPersonColumnName) },
If(!(_user.Email in _peopleTable.Email),
With({_SPuser:
{
Claims:"i:0#.f|membership|" & Lower(_user.Email),
Department:"",
DisplayName: _user.DisplayName,
Email: _user.Email,
JobTitle: "",
Picture: ""
}
},
With({_newList:
Ungroup(
Table(
{Items: Table(_SPuser)},
{Items: _peopleTable}
),
"Items"
)
},
UpdateIf(yourDataSource, ID=1, {MultiPersonColumnName: _newList})
)
)
)
)
For the most part, you'll just need to adjust the _peopleTable definition and the UpdateIf statement for your needs. All the rest needs no adjustment.
I hope this is helpful for you.
Thank you for your reply. I just wanted to append the current user in Multi selection people column.
No need to Patching and update the record, since I have submit button to Submit the Form.
So, I just wanted to append the current users who is submitting the form. No need to add the current user If that person already there in the People column. I mean he would have already submitted the form before.
@Anonymous
Yes, this is the formula I provided you. The form will not automatically do this for you. However, if you want to incorporate this into your form, then you will need to look at your Update property for the datacard that contains this column.
If you are NOT exposing a multi-select combobox and simply want to do this behind the scenes, then the formula would be:
With({_user: User(),
_peopleTable: ThisItem.MultiPersonColumnName },
If(!(_user.Email in _peopleTable.Email),
With({_SPuser:
{
Claims:"i:0#.f|membership|" & Lower(_user.Email),
Department:"",
DisplayName: _user.DisplayName,
Email: _user.Email,
JobTitle: "",
Picture: ""
}
},
Ungroup(
Table(
{Items: Table(_SPuser)},
{Items: _peopleTable}
),
"Items"
)
)
)