AnsweredAssumed Answered

Pre-populate a people picker field with the current user's manager's name

Question asked by suolon on Jan 16, 2015
Latest reply on May 16, 2017 by tposzytek

I found this link and have followed it on a form that have created using Nintex:

 

Nintex Forms: Automatically populating the new people picker control - Wow, So SharePoint, Much information

 

But for some reason it's not populating the field at all.

 

Any idea why this isn't working?  I got this working before implementing Nintex (but not sure how I can incorporate this into Nintex Form, by using the following code:

 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="/siteassets/scripts/sputility.min.js"></script>

<script>

// wait for the window to load

$(window).load(function () {

     var userid = _spPageContextInfo.userId;

 

function GetUserLogin() {

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 : QuerySuccess,

  error : QueryError

});

}

 

function QuerySuccess(data, request){

  var loginName = data.d.DisplayName;

        var myManager = data.d.UserProfileProperties.results[15].Value;

  //$("div[title='Employee Name']").val(loginName);

  SetAndResolvePeoplePicker("Employee Name",loginName);

  SetAndResolvePeoplePicker("Approval Manager",myManager);

}

 

 

function QueryError(error) {

  alert(error);

}

 

function SetAndResolvePeoplePicker(fieldName, userAccountName) {

        var controlName = fieldName;

        var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");

        var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");

        var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];

 

        peoplePickerEditor.val(userAccountName);

        spPeoplePicker.AddUnresolvedUserFromEditor(true);

    }

 

GetUserLogin();

 

});

</script>

Outcomes