cancel
Showing results for 
Search instead for 
Did you mean: 
suolon
Nintex Newbie

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

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 info...

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>

Labels: (1)
Tags (1)
Reply
11 Replies
johncharles
Nintex Newbie

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

Hello Soulon,

I don't know if you still need this - However!

Tom's solution worked well for me in SP2013 and Nintex Forms 2013 2.3.4

I did need to follow the instructions exactly - the order of includes was important:

And entering the CSS class was important:

Download Tom's Libraries from his link - reference them correctly - and then it works!

Reply
suolon
Nintex Newbie

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

Hi John,

I can’t seem to get this to work on Office 365 though. I feel that I’m missing something, but still can’t seem to figure it out.

Thanks for the response, I will look into what you have.

0 Kudos
Reply
Not applicable

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

Hi Suolon Hu

Have you tried something like this for your Office 365?

Re: Nintex forms for Office 365 - Populate People Picker

Reply
suolon
Nintex Newbie

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

Hi Cellou,

I'm looking at the code now and trying out, but I'm getting the following error:

"Object doesn't support property or method '_additem' "

Reply
Not applicable

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

I am having same issue in o365. Did you get any solution for this ?

0 Kudos
Reply
glenda
Nintex Newbie

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

Suolon Hu​, did you manage to solve this?

Can't you use the userProfileLookup function for this purpose?

  • Add a calcualted value field
  • Dig into the properties and define your function with userProfileLookup(Current User, "Manager").
  • Test out your form

You could use the "Current User" from the common section, otherwise you could create a variable. If you get the login name back from your manager, you could store the result in a form variable and use the userProfileLookup(ManagerVariable, "PreferredName") function to populate.

Goodluck!

Reply
suolon
Nintex Newbie

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

Hi Glenda,

No, I never got this to work.

I don't see the userProfileLookup function for Nintex Forms for Office 365.

0 Kudos
Reply
alexv1
Nintex Newbie

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

Here is how I did it....

  1. Add a Calculate Value to the form, and create a rule to hide it.
  2. Add this formula to the Calculated control: userProfileLookup( userProfileLookup(  Current User, "Manager"), "PreferredName")
  3. Add the javascript below to the form, change the control IDs (peoplecontrol, calculatedvaluecontrol) to your controls.
  4. The 750ms delay gives the Calculated control enough time to make the 2 userProfileLookup calls, 750 was a safe number and is not perceivable by users. You may have to increase it if you have a slow network, test test test.

  

NWF$(document).ready(function()

{

   NWF.FormFiller.Events.RegisterAfterReady(function()

    {

     setTimeout(function(){  

     var ins = new NF.PeoplePickerApi('#' + peoplecontrol);

     var currentuser = NWF$('#' + calculatedvaluecontrol).val();

     ins.search(currentuser).done(function (data)

     {      

        ins.add(data[0]);

      });

}, 750);

0 Kudos
Reply
Warwick
Nintex Newbie

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

Hi Alex, I take it your solution was for a on-premises version as the runtime userProfileLookup is not available in Office 365.

0 Kudos
Reply