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

In this post, we will discuss how to Auto-populate current logged in username in SharePoint 2010 People Picker control. Here we will do by using SPServices js file provided by Codeplex. We will not use any server-side code.

Here my requirement is I have a SharePoint list that has a people picker control in it. I want to show the logged in username or email id there whenever a user tries to add an item to the list. So here we will put the code js code in the Default New Form. For this Open the List -> Customize List -> then Form Web Parts -> then click on Default New Form as shown in the fig below:


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

This will open the Default New Form in Edit mode. Here you click on Add a Web Part and then add a Content Editor Web Part. Once the web part added, go to format text and then Markup and then Edit Source as shown in the fig below.

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

You can download the SPService from the CodePlex URL and also you can download the jQuery required version from jquery website and put it in your site assets library.

In the source editor put the below code:

Auto populate urrent logged in user name in SharePoint 2010 People Picker control using SPServices

Method-1

<script language=”javascript” type=”text/javascript” src=”http://win-pfcp2dgt8di/sites/EnjoySharePoint/SiteAssets/jquery-1.5.1.min.js”></script>

<script language=”javascript” type=”text/javascript” src=”http://win-pfcp2dgt8di/sites/EnjoySharePoint/SiteAssets/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>

Example-2
<script language=”javascript” type=”text/javascript” src=”/teams/EnjoySharePoint/Style%20Library/jquery-1.5.1.min.js”></script>
<script language=”javascript” type=”text/javascript” src=”/teams/EnjoySharePoint/Style%20Library/jquery.SPServices-2014.01.min.js”></script>
<script language=”javascript” type=”text/javascript”>
$(document).ready(function() {
var userName= $().SPServices.SPGetCurrentUser();
$().SPServices.SPFindPeoplePicker({
peoplePickerDisplayName: “Owner”,
valueToSet: userName,
checkNames: true
});
});
</script>

You may like following SharePoint tutorials:


Now the current user will populate in the people picker control.

This will work in SharePoint 2010. I tried in SharePoint 2013 but it did not work, If anyone has a solution for SharePoint 2013, Please let me know.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →