I was trying to find a simple way to get an Employee's Manager in a People field on a form. You can use a Calculated Field to display the Manager but I couldn't connect that directly to a People column. Also, in some cases, the Manager a person reports to is not always the Manager in their User Profile, so I wanted to give users the ability to select the appropriate manager as an alternative option. I found a few posts that used JavaScript to do this, but they seemed needlessly complicated. I used People Picker Extensions and JavaScript events in Nintex Forms as references and came up with a simpler solution (also, I'm using Nintex Forms Enterprise version 1.12.2.20).Â
Â
First, I added a People Field for the Employee:
- Formula:Â Current User
- Store Client ID in JavaScript variable: Yes
- Client ID JavaScript variable name:Â Employee
Second, I added a People Field for the Manager:
- Default Value Source:Â Use connected field's default value
- Store Client ID in JavaScript variable: Yes
- Client ID JavaScript variable name:Â Manager
Then, I added a Calculated Field to the form with the following attributes:
- Formula: userProfileLookup(Employee,'Manager')
- Store Client ID in JavaScript variable: Yes
- Client ID JavaScript variable name: ManagerLan
Finally, I added the code into the Custom JavaScript in the form Settings:
Â
NWF.FormFiller.Events.RegisterAfterReady(function() {
  NWF$(document).ready(function(){
   GetManager();
  });
  var emp = new NF.PeoplePickerApi('#'+Employee);
  emp.added(function(){
   var people = NWF$('#' + Employee).val().split(';');
   if(people.length > 2){
     emp.remove(people{0]);
   }
   GetManager();
  });
});
Â
function GetManager(){
  setTimeout(function(){
   var val = NWF$('#' + ManagerLan).val();
   var mgr = new NF.PeoplePickerApi('#'+Manager);
   if(val.length > 0){
     mgr.clear();
     mgr.search(val).done(function(data){
      mgr.add(dataÂ0]);
     });
   }
  }, 1000);
}
Â
The Manager people picker gets populated: