Skip to content

Instantly share code, notes, and snippets.

@Aymkdn
Last active October 27, 2016 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aymkdn/da1e498690dc9b957ea4f5c93a1a05a7 to your computer and use it in GitHub Desktop.
Save Aymkdn/da1e498690dc9b957ea4f5c93a1a05a7 to your computer and use it in GitHub Desktop.
Examples to retrieve a manager in Sharepoint 2013
// Retrieve Manager for a username
// using REST API
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = 'domain\\login';
// I suppose you use jQuery
$.ajax({
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
alert("The manager username is:" + data.d.ExtendedManagers.results.slice(-1)[0]);
},
error: function (data) {
console.log(JSON.stringify(data));
}
});
// Retrieve Manager for the current user
// using REST API
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
$.ajax({
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
alert("The manager username is: " + data.d.ExtendedManagers.results.slice(-1)[0])
},
error: function (data) {
console.log(JSON.stringify(data));
}
});
// Retrieve Manager for a username
// using SharepointPlus -- http://aymkdn.github.io/SharepointPlus/symbols/%24SP%28%29.html#.people
var username = "domaine\\login";
$SP().people(username, function(people) {
alert("The manager username is: " + people["Manager"])
})
// Retrieve Manager for the current user
// using SharepointPlus -- http://aymkdn.github.io/SharepointPlus/symbols/%24SP%28%29.html#.whoami
for the $SP().whoami(function(people) {
alert("The manager username is: " + people["Manager"])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment