EnjoySharePoint YouTube Channel

Get manager of current SharePoint user using SPServices and GetUserProfileByName


This SharePoint tutorial we will discuss how we can get manager of current SharePoint user using SPServices and GetUserProfileByName. Learn SPServices for SharePoint 2010/2013/2016 or SharePoint Online.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

We get the current user’s manager and put the value into a Person or Group column in a list. This one only works in SharePoint Server 2010 & SharePoint Foundation, because the UserProfileService Web Service is only available there.

The code is relatively straightforward: a call to SPServices to get the results from GetUserProfileByName and then a little more code to poke it into the appropriate Person or Group column. In this case, the Person or Group column is called ‘Manager’.

Below is the code:



<script type=”text/javascript” src=”../../JSLibrary/jquery-1.3.2.min.js”></script>
<script type=”text/javascript” src=”../../JSLibrary/jquery.SPServices-0.4.8.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function () {
var managerName;
var userName = $().SPServices.SPGetCurrentUser();
$().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);
}
});
var peoplepicker = $(“tr:contains(‘Reporting Manager’):last”).find(“div[title=’People Picker’]”);
peoplepicker.html(managerName);
});
</script>

The available values from GetUserProfileByName in sharepoint 2010 environment are:

– UserProfile_GUID
– AccountName
– FirstName
– LastName
– PreferredName
– WorkPhone
– Office
– Department
– Title
– Manager
– AboutMe
– PersonalSpace
– PictureURL
– UserName
– QuickLinks
– WebSite
– PublicSiteRedirect
– SPS-Dotted-line
– SPS-Peers
– SPS-Responsibility
– SPS-Skills
– SPS-PastProjects
– SPS-Interests
– SPS-School
– SPS-SipAddress
– SPS-Birthday
– SPS-MySiteUpgrade
– SPS-DontSuggestList
– SPS-ProxyAddresses
– SPS-HireDate
– SPS-LastColleagueAdded
– SPS-OWAUrl
– SPS-ResourceAccountName
– SPS-MasterAccountName
– Assistant
– WorkEmail
– CellPhone
– Fax
– HomePhone

You may like following SPServices SharePoint 2010 tutorials:

Hope this SharePoint 2010 spservices examples we will display how to Get manager of current SharePoint user using SPServices and GetUserProfileByName in SharePoint 2010.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →