Get manager ptr userul curent din javascipt


//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js

$(document).ready(function () {
var userid = _spPageContextInfo.userId;
function GetCurrentUser() {
//var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties/";

var requestHeaders = { "accept" : "application/json;odata=verbose" };
$.ajax({
url : requestUri,
contentType : "application/json;odata=verbose",
headers : requestHeaders,
success : onSuccess,
error : onError
});
}
function onSuccess(data, request){
//var loginName = data.d.Title;
console.log(data);
var loginName = data.d.DisplayName;
var myManager = data.d.UserProfileProperties.results[15].Value;

//Use the following code to find Manager if results[15] is not Manager in future SharePoint
//var myManager = '';
//var x = data.d.UserProfileProperties.results;
//for (var i = 0; i < x.length; i++) {
// if (x[i].Key == 'Manager') {
// myManager = x[i].Value;
// break;
// }
//}

SetUserFieldValue("Employee Name",loginName);
SetUserFieldValue("Approval Manager",myManager);

}
function onError(error) {
//alert(error);
}
function SetUserFieldValue(fieldName, userName) {
var _PeoplePicker = $("div[title='" + fieldName + "']");
var _PeoplePickerTopId = _PeoplePicker.attr('id');
var _PeoplePickerEditer = $("input[title='" + fieldName + "']");
_PeoplePickerEditer.val(userName);
var _PeoplePickerOject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];
_PeoplePickerOject.AddUnresolvedUserFromEditor(true);
}
GetCurrentUser();
});

Anunțuri

Lasă un răspuns

Completează mai jos detaliile tale sau dă clic pe un icon pentru a te autentifica:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s