Sunday, March 13, 2011

Auto populate current logged in user name in SharePoint 2010 People Picker control

Follow the steps below to Auto populate current logged in user name in SharePoint 2010 People Picker control:
1) Create a scripts library in your site (or use the one you currently use to store your Javascript/*.js files)
2) Download the latest version of the JQuery file from here -
3) Dowload the latest version of the SPServices JQuery library from here - or
4) Copy the above *.js files (namely "jquery-1.5.1.min.js" and "") to the scripts folder created in Step 1
5) Open the form/page (such as NewForm.aspx) where you want to default the People Picker control to the current user logged in and add the following script at the end of the page (preferably below the end style tag:

<script language="javascript" type="text/javascript" src="/board/scripts/jquery-1.5.1.min.js"></script>
<script language="javascript" type="text/javascript" src="/board/scripts/jquery.SPServices-0.6.0.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
 var userName = $().SPServices.SPGetCurrentUser({
  fieldName: "Name"
 $("textarea[title='People Picker']").val(userName);
 $("div[title='People Picker']").text(userName);

Note - you need to replace the src property values above to reflect the correct path to the Javascript files downloaded in above steps and saved in the "scripts" folder.


Török said...

Thank you very much!
I've been looking for a good solution.

Hungarian Girl

cecri_btech_girls said...

Its really Awesome... It works for me.

Bento22 said...

If there is more then one people picker how to only populate the first one?

Ratikanta said...

If there is more than one people picker then go with the following
$("textarea[title='People Picker']:eq(2)").val(userName); $("div[title='People Picker']:eq(2)").text(userName); });

Bijay Kumar Sahoo said...

Hi Here I am trying to use this in sp2013. But the values are not writting to the people picker control. Can any one tell me.

$("textarea[title='People Picker']").val(userName);
$("div[title='People Picker']").text(userName);

Is there is something change in sharepoint 2013

Ajay Singh Raghuwanshi said...

for me, below alert is providing nothing, 'userName' is blank, any idea?

var userName = $().SPServices.SPGetCurrentUser({
fieldName: "Name"
alert("name: "+userName);