cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DeannaT
New Member

How to Default a People Picker to current user & save to SharePoint List source

Hi,

 

I am trying to create a very simple PowerApp based on a SharePoint list.  This list has a Person field.  When I initially create the PowerApp, if the user types in a person's name and chooses one, it saves fine.  As soon as I try to default the Person field in the PowerApp to "current user" (using any of the User(). syntax options), my PowerApp stops saving back to the SharePoint source list. 

 

Any ideas?

48 REPLIES 48

This is quite tricky...  

  • You need to add the O365 Connector to the screen holding the form
  • You need to set the update property of the data card holding the Default User Information ( A dropdown in my case) to the JSON Object that SharePoint expects.... 
  • Using the command Office365Users.MyProfile() grab the currently logged in user from the Office 365 User Service Connector.  I am sure you can set it to someone else if you play around with it a bit... I have not done that yet.. 

 

here goes...

 

1 – Select the Screen holding the form

2 – Select  View Menu then the Tab Called  > Data Sources > Add Data Source >  then add Office 365 Users

3 – Select the PeoplePicker DataCard in PowerApps and Unlock it 

4 – Put the following in the Default for the DataCard to set default to Current User in a PowerApps form ( called 

              If( Account_Detail_Edit_Display_Long_1.Mode = FormMode.New,

                 Office365Users.MyProfile(),

                 ThisItem.OwnerA)

 

Where “Account_Detail_Edit_Display_Long_1” is the form name and “ThisItem.OwnerA” is the PeoplePicker field in the SharePoint list

 

5 - Now put the following in the Update Property for that DataCard within the Form

     If( Account_Detail_Edit_Display_Long_1.Mode = FormMode.New,
         {
             '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
              Claims:"i:0#.f|membership|" & Lower(User().Email),
              Department:"",
              DisplayName:User().Email,
              Email:User().Email,
              JobTitle:"",
               Picture:""
         }, SalesPerson_DD.Selected)

 

Works great for me

Updated response above with info needed in the Default and Update properties

Anonymous
Not applicable

Set Default Property of control 

 

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

Or 
If(EditForm1.Mode = New, Office365Users.MyProfile(), ThisItem.calumnName)

This worked for me and should be the recommended solution.

The 2nd option here worked great for me  to set the default as current user, however it won't update the sharepoint list with this info?  Any ideas on what I'm missing  If I change the user it updates fine.

crosbd
Frequent Visitor

Sounds like you might have missed step #5 in the steps from @skylitedave .

 

Did you do this step?

5 - Now put the following in the Update Property for that DataCard within the Form

     If( Account_Detail_Edit_Display_Long_1.Mode = FormMode.New,
         {
             '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
              Claims:"i:0#.f|membership|" & Lower(User().Email),
              Department:"",
              DisplayName:User().Email,
              Email:User().Email,
              JobTitle:"",
               Picture:""
         }, SalesPerson_DD.Selected)

So no I didn't actually use Skylite Daves' solution I just used the oneliner default from above anonymous..   So it gave default value in field fine but just didn't pass to Sharepoint  no matter what I did with the Update parameter. I will try the other but can't help thinking there must be something a little simpler?  

rebeccas
Community Champion
Community Champion

If I want the data card to default to the current user I set a variable at the start that is = Set(_CurrentUser, User())

 

Then on the combo box I put as the DefaultSelectedItems: {DisplayName: _CurrentUser.FullName}

^ this does nothing but show the name so if you are hiding it then it is no necessary

 

Then on the cards Update value I put :  

 

If(ComboBox.Selected.DisplayName=_CurrentUser.FullName, 
{DisplayName: _CurrentUser.FullName, 
Claims:"i:0#.f|membership|" & Lower(_CurrentUser.Email),
Department:"",
Email: _CurrentUser.Email,
JobTitle:"",
Picture:""}, ComboBox.Selected)

 

This is basically saying to default to the current user but if they change it then take that instead. I have seen several people say "easier" ways of doing it but I have been using this for a while and it works great...the other ways I have seen I have had trouble with them. This works 100% of the time for me.

Thanks @rebeccas  i think that might work perfectly for me 🙂  Have to go now but will try later.. Can I just clarify when you say

 

"If I want the data card to default to the current user I set a variable at the start that is = Set(_CurrentUser, User())"

 

Do you mean on the visible property of the screen?

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,945)