SharePoint 2013 Populate Manager name using SPServices

This spservices tutorial explains how to populate or retrieve manager name using SPServices in SharePoint 2013/2016 or SharePoint Online.

Recently I got a requirement where I need to retrieve manager name using client object model code. Thanks, Sagar for giving the code sample. Here we will discuss how we can get the Manager name using SPService

Here we need to give reference to the SPService.js file which you can download from this GitHub URL. And also we need to give the jQuery reference.

Then you can add a script editor web part to the page and add the below code in it.

<script type=”text/javascript” src=”http://win-pfcp2dgt8di/sites/EnjoySharePoint/SiteAssets/jquery-1.3.2.min.js”>
</script>
<script type=”text/javascript” src=”http://win-pfcp2dgt8di/sites/EnjoySharePoint/SiteAssets/jquery.SPServices-0.4.8.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function () {

var managerName;

var userName = $().SPServices.SPGetCurrentUser();

alert(userName);

$().SPServices({

operation: “GetUserProfileByName”,
async: false,
AccountName: userName,
completefunc: function (xData, Status) {
managerName = $(xData.responseXML).text();
var managerLength = managerName.length;

var indexofManager = managerName.indexOf(“Manager”);
managerName = managerName.substring(indexofManager + 13, managerLength);
var indexOffalse = managerName.indexOf(“false”);

managerName = managerName.substring(0, indexOffalse);
}

});

alert(managerName);

});
</script>

Once you will save the page, it will display first display the user name and then the manager name in the alert box.

You may like following SPServices SharePoint 2013/2010 tutorials:

Hope this will be helpful to retrieve manager name in SharePoint 2013 using SPServices.

free sharepoint training

SharePoint Online FREE Training

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

envelope
envelope

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

>