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

Re: PowerApps People picker - Current User

Thanks for this answer! 

 

I just wanted to extend this one more step. Is there a way to gather the existing selected users in a people picker field and add the currently logged in user? By using the above code I can get my own name to populate in a powerapps form but it erases all of the existing names. If i replace the above with Parent.Default the form will populate with the existing selected names.

 

Is there an easy way to add the currently logged in user to the Parent.Default?

Sienna
Level 10

Re: PowerApps People picker - Current User

 
robgm
Level: Powered On

Re: PowerApps People picker - Current User

was this just an empty reply?

jatherton
Level: Power Up

Re: PowerApps People picker - Current User

I have tried the above code, everything seems set right, but it does nothing.  am I missing something?

 

If(RequestForm.Mode = New,{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:Concatenate("i:0#.f|membership|",Office365Users.Manager(User().Email).Mail),
DisplayName:Office365Users.Manager(User().Email).DisplayName,
Email:Office365Users.Manager(User().Email).Mail},
ThisItem.OverridingSupervisor)

Super User
Super User

Re: PowerApps People picker - Current User

There has been some changes that make working with person/group values a little easier. I have provided some sample code below. In my example you need to set a couple of variables and you can do this in the OnVisible, OnStart, add to a button or add it to the beginning of the default formula to quickly test and see if it is going to work.

 

The sample default formula would go into the DefaultSelectedItems property of the data card value. You might have to change "EditForm1" to the name of your form but the rest should be the same if you use the variables.

 

//Set Current User and Manager variables
Set(gvCurrentUser, Office365Users.MyProfileV2()); 
Set(gvCurrentManager, Office365Users.ManagerV2(gvCurrentUser.userPrincipalName))

//Default formula for the data card value
If(EditForm1.Mode = FormMode.New,
    {
        DisplayName: gvCurrentManager.displayName,
        Claims: "i:0#.f|membership|" & gvCurrentManager.userPrincipalName
    },
    Parent.Default
)


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Lakely15
Level: Powered On

Re: PowerApps People picker - Current User

Hi @Jeff_Thorpe, would it be possible to filter by the value that this formula returns? 

If(EditForm2.Mode = New,{
  '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
   Claims:Concatenate("i:0#.f|membership|",User().Email),
   DisplayName:User().FullName,
   Email:User().Email
    }, 
ThisItem.PersonGroup)

I have been struggling to filter by a people field on my SharePoint list. Keep running into the "Delegation" warning.

Super User
Super User

Re: PowerApps People picker - Current User

You will always get the delegation warning when filtering by a name field. The name field is a complex field type which isn't delegable in SharePoint. If your list is with in the delegation limit then the warning isn't that important unless you are seeing performance issues. If your list has more items than your delegation limit then you could be missing data when filtering.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Brice235i
Level 8

Re: PowerApps People picker - Current User

Hi just updating this reply.. in case anyone wants to use.  This now works without error.  The onChange formula was originally incorrect.

 

This is what I have:

 (datacardvalue35 refers to the Requestor/submitter field and datacardvalue36 refers to the Manager field)

So the app opens with the Requestor field defaulted to the current user and the manager field defaulted to the current user's manager.  Quite often, administrative staff submit a request form on behalf of someone else so they overwrite the Requestor field to this person...  The manager field updates to this new person's manager. 

 

Welcome Page

OnStart

Set(gvCurrentUser, Office365Users.MyProfileV2());

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

 

 

EditScreen

Current user (requestor) 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))

 the about formula was causing a connection error...  please use below instead:

Corrected onChange Formula:
If(Len(DataCardValue35.Selected.Email)>0, Set(gvCurrentManager, Office365Users.ManagerV2(DataCardValue35.Selected.Email));Set(varManager, gvCurrentManager))

 

Current user (requestor) 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

Update

DataCardValue36.Selected

 

 

Super User
Super User

Re: PowerApps People picker - Current User

I just tried a couple of my apps that use the V2 lookup for manager and they are working. Based on the error it seems to be having an issue with OnStart or OnChange. Have you tried removing the connector and re-adding it?



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Brice235i
Level 8

Re: PowerApps People picker - Current User

Thanks Jeff, yes I removed and reconnected.... What's worse is that I removed it all together so the users could at least use the app again and type their details in.... however the error persists even after removing...  Cleared the cache. Don't understand.

 

Actually when you save remove and reconnect... do you mean just to remove from the OnStart screen, save and readd?

 

I wondered if there was something wrong with the OnChange code...  Trying a few things now and will start a new test app to see if I can figure it out.

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,801)