Selecting User Profile values from the people picker fields

Document created by AdisJ Employee on Aug 17, 2017Last modified by ChristofN on Feb 25, 2019
Version 4Show Document
  • View in full screen mode

Very often there is a need to select the User Profile properties for another user apart of "my user" (the user that is currently logged in). Since this is not implemented in skybow Solution Studio and skybow Rich Forms out of the box, due to the issue with permissions and security (the user who is querying the user profile information needs to have appropriate permissions to actually do it), here is a workaround how to implement this manually.

In the use case below, there are two fields on the form: a People Picker field bound to the field with internal name "PersonField", and a Text field, bound to the field with internal name "DepartmentField". The goal is, that when a person is selected in the people picker field ("PersonField"), that the "DepartnemtField" is automatically populated with the Department value from that user's profile.


In the "Behavior" ribbon group of the "DepartmentField", in the "Calculated" value, the following "Function code" script should be set.


Please note, that in lines 2 and 39 proper field names should be set for people picker and text field, and in the line 37 proper user profile property name.  

Important: since this script will always be executed in the user context, if logged user does not have rights to read User Profile property values, the script will not work for that user.


var personProperties;
var targetUser = [[PersonField.LoginName]];

function LoadFiles() {
var defer = jQuery.Deferred();
if (typeof SP.UserProfiles == 'undefined') {
var scriptKey = 'SP.UserProfiles.js';
SP.SOD.registerSod(scriptKey, '/_layouts/15/SP.UserProfiles.js');
SP.SOD.loadMultiple(['SP.UserProfiles.js'], defer.resolve);
} else {
return defer.promise();

function getUserProperties(targetUser) {

// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();

var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

// Get user properties for the target user.
// To get the PersonProperties object for the current user, use the
// getMyProperties method.

personProperties = peopleManager.getPropertiesFor(targetUser);
// Load the PersonProperties object and send the request.
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);

// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
try {
// Get a property from the UserProfileProperties property.
var messageText = personProperties.get_userProfileProperties()["Department"];

var inputController = jQuery('[fieldname="DepartmentField"]').closest('.ard-formfield').data('Controller');
catch(e) {

// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
alert("Error: " + args.get_message());

if(targetUser) {