Friday 13 July 2012

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

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 - http://code.jquery.com/jquery-1.5.1.min.js
3) Dowload the latest version of the SPServices JQuery library from here - http://spservices.codeplex.com or http://spservices.codeplex.com/releases/55660/download/171214
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);
});
</script>

No comments:

Post a Comment