Auto-Populating Fields from Active Directory Fields

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
axt3641
Posts: 1
Joined: Wed Nov 11, 2020

11 Nov 2020

Hi SPForms Community!
I'm trying to auto-populate information from AD when a user selects a specific field.

When the user selects an item from the "Employee" People Picker, there are a few subsequent drop down boxes that should be populated:
a. Department
b. Job Title
c. Supervisor

I have found a few articles on the Forum that helps point to referencing this but further elaboration would be much appreciated.
Links I referenced:
viewtopic.php?f=1&t=1997&p=7881&hilit=A ... tory#p7881
viewtopic.php?f=1&t=434&p=1739&hilit=Ac ... tory#p1739
https://zimmergren.net/sharepoints-hidd ... tion-list/

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

12 Nov 2020

Hello axt3641,

You can try the following code to retrieve user profile properties:

Code: Select all

SP.SOD.executeOrDelayUntilScriptLoaded(function(){
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
  $.getScript(scriptbase + "SP.UserProfiles.js", getUserProperties);
});
function getUserProperties() {
  var targetUser = fd.field('Employee').value().Key;
  var clientContext = new SP.ClientContext.get_current();
  var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
  personProperties = peopleManager.getPropertiesFor(targetUser);  
  alert(personProperties);
  clientContext.load(personProperties);
  clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}
function onRequestSuccess() {
  fd.field('FieldName').value((personProperties.get_userProfileProperties()['PropertyName']));
}
function onRequestFail(sender, args) {
  console.log('Error');
}
}, "sp.js");
Where PropertyName is the name of the property, e.g. Department.

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

09 Dec 2020

Hello Mnikitina,

I have a similar problem. When the user selects an employee the list fields E-Mail and phone should be filled from the Active Directory. Can you give me an example?

Best wishes
Tom

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests