Set a SharePoint people field with jQuery

When I talked about how to update fields in SharePoint, I was talking about the easy stuff: input fields and stuff. Now, I wanted to update / set a SharePoint people field on my form.
I did some googling and found a solution by Marc D. Anderson (in my opinion he is THE authority on sharepoint jQuery 😉 ) but I couldn’t get that to work here.

I also found a really easy solution by Dave Cavins who uses the class to define the people picker. Only bad thing with this solution is that it updates all people pickers:

Combined with SPServices it gives the following result to automatically fill in the current user:

<script type="text/javascript">
$(document).ready(function() {
   $('div.ms-inputuserfield').text($().SPServices.SPGetCurrentUser({fieldName: "Title",debug: false}));
});
</script>

In the mean time, a far better solution has arisen (like the comment from Marc says) that allows you to address a specific SharePoint people field with the help of the almighty SPServices:

</pre>
$().SPFindPeoplePicker({

peoplePickerDisplayName: "",
valueToSet: "",
checkNames: true
});

This code allows you to set a SharePoint people field by pointing to its name, add the value you want it to be and if you want it “checked”.

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


5 thoughts on “Set a SharePoint people field with jQuery”

  1. Wow, thanks Marc !!
    I already checked out the solution this week and I will use that in future projects!!

  2. Wow, Thanks.
    Just spend 2 hours getting it to work. You just made me do it in 15 seconds!

  3. Hello,
    I want People Picker Control in SharePoint 2010.I tried above solution, can you please tell me what jquery reference we have to refer, in my case user is not resolving

Leave a Reply

Your email address will not be published. Required fields are marked *