Preset field value
Posted: 12 Sep 2016
I have this script to read out the manager oft the current user.
I know there is some stuff missing.
What do i have to change to make it work?
var userid = _spPageContextInfo.userId;
function GetCurrentUser() {
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){
console.log(data);
var loginName = data.d.DisplayName;
var myManager = data.d.UserProfileProperties.results[15].Value;
SetUserFieldValue("pfer",loginName);
SetUserFieldValue("ri2o",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];
}
GetCurrentUser();
Thx for your help and best regards,
Tim
I know there is some stuff missing.
What do i have to change to make it work?
var userid = _spPageContextInfo.userId;
function GetCurrentUser() {
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){
console.log(data);
var loginName = data.d.DisplayName;
var myManager = data.d.UserProfileProperties.results[15].Value;
SetUserFieldValue("pfer",loginName);
SetUserFieldValue("ri2o",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];
}
GetCurrentUser();
Thx for your help and best regards,
Tim