Dealing with SharePoint people-picker field in PowerApps customz ized SharePoint list form and canvas application
Despite Microsoft promotes PowerApps as no-code or low-code solution, which is easy to create responsive applications, usually PowerApps creation process causes lots of troubles and pain. However, in some interesting cases I find "technical limitations" as very interesting challenges and become really happy and proud of myself once solution is found.
Another PowerApps project is on the table and I have to develop document request approval solution. Data is stored in SharePoint Online list and PowerApps is used to create customized list form. Seems to be completely doable, but once again I faced with some really interesting case.
The Company has got two geographical locations, which is stated by author once new request is created. Depending the selected location the last approval role of "Document Manager" must be assigned to responsible for the location employee. So it is clear, that on SharePoint side I have a people picker field to store Document Manager and there might be various technical implementations.
Depending on "Request Location" field value set "Default" and "Default selected item" properties of people picker to specific users. But this solution has huge cons - users woulf be hardcoded, so there would be hard to deal with requests in case Document Manager should be changed (in case of leave or vacation, etc.). Of course, we could have some "settings" to allow admins to modify roles using some hidden fields or something, but this is not a good and user friendly approach.
I think it is not a secret, how it is possible to set default value for the people picker control -set "default" and "default selected items" propertis to something like below:
????{??
????'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",??
????DisplayName:"Peter Smith",??
????Claims:"i:0#.f|membership|[email protected]",??
????Department:"",??
????Email:"[email protected]",??
????JobTitle:"",??
????Picture:""??
????},
So taking all this into consideration the useage of groups could help. Client asked to create SharePoint groups, so SharePoint site owner would be able to manage them without any external help (in case of Azure AD groups AD admin help would be needed).
It seems to be no problem to use SPO groups, native SPO people picker control allows to set group as its value, it is possible to chose group from the available list in PowerApps. But I have never used SPO group as default value of the control in PowerApps.
There is known info on how to set Azure AD group as default value:
领英推荐
{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
Claims:"c:0o.c|federateddirectoryclaimprovider|group objectID",
Department:"",
DisplayName:"groupname Members",
Email:"group email address",
JobTitle:"",
Picture:""
},
But SPO group does not have "Claims". Unfortunately, I was not able to find any usefull information in net.
So I stack for a few days and focused on other controls of the form. I had "Plan B" which was to have Power Automate flow to assign group to the field based on group ID using REST api call. But I still wanted to have all the logic in the form.
Finally, I came up with an idea to perform some test. Firstly, I decided it might be possible to the some valid data using REST call to the list. But the response contained just group ID and has not helped me much.
Finally, I created a simple Power Automate workflow on item creation and used "Get item" action. I assigned SPO group to the people picker field and executed the flow. I was really surprised with results:
DocumentManage
0
@odata.type : "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
Claims : "DokuWF_STAG_DM"
DisplayName : "DokuWF_STAG_DM"
Email : null
Picture : null
Department : null
JobTitle : null
[email protected] : "#Collection(Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser)"
DocumentManager#Claims
0 : "DokuWF_STAG_DM"
DocumentManager#[email protected] : "#Collection(String)"
FirstReminderSent : false
SecondReminderSent : false
EscalationReminderSent : false
AuthorComment : "Test group"
Created : "2022-06-22T07:57:19Z"
Modified : "2022-06-22T07:57:19Z"
So, all the fields are filled in with group display name!
So just assigned below record to "default" and "default selected items" properties of people picker and all works nicely:
? ? ? ? {??
? ? ? ? '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",??
? ? ? ? DisplayName:"Group Name",??
? ? ? ? Claims:"Group Name",??
? ? ? ? Department:"",??
? ? ? ? Email:"",??
? ? ? ? JobTitle:"",??
? ? ? ? Picture:""??
? ? ? ? },
Hope, this could be useful for someone :)