Text Value of People Picker

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

27 Sep 2017

I am trying to get the value of two fields and concatenate the data and post into another field.
Field 1 - Source of Lead is a Lookup field
Field 2 - Referring Employee Name is a people picker field

My code is below: -

Code: Select all

// Function to Set Original Source of Contact Field
function setOriginalSourceOfContactEmployeeReferral () {
	var sourceOfLeadLookupText = fd.field('Source_x0020_of_x0020_Lead').control('data')['Title'];
	var referringEmployeeName = fd.field('Referring_x0020_Employee_x0020_N').control('ready', function() {
		var selectedUsers = fd.field('Referring_x0020_Employee_x0020_N').value();
		for (var i = 0; i < selectedUsers.length; i++);
	});
	fd.field('Original_x0020_Source_x0020_of_x').value(sourceOfLeadLookupText + ' - ' + referringEmployeeName);
} 
What this code returns into the Original Source of Contact field is - Employee Referral - [object Object]
What I would like returned is - Employee Referral - Employee Name

Help appreciated please.

Thanks

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Sep 2017

Once you get the object with Person, you can try calling DisplayText method on it, it should get you the correct result. For example, this code should work for multiple people:

Code: Select all

var people = fd.field("People").value();
var names = [];
for(var i = 0; i < people.length; i++) { 
    names.push(people[i].DisplayText); 
}
Cheers

User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

28 Sep 2017

Hi Nikita,

Still no luck with this one, still returns [object - object], even if I put the code in the console that is the result I get? just to confirm my code is now -

Code: Select all

// Function to Set Original Source of Contact Field
function setOriginalSourceOfContactEmployeeReferral () {
	var sourceOfLeadLookupText = fd.field('Source_x0020_of_x0020_Lead').control('data')['Title'];
	var referringEmployeeName = fd.field('Referring_x0020_Employee_x0020_N').control('ready', function() {
		var people = fd.field("Referring_x0020_Employee_x0020_N").value();
		var names = [];
		for(var i = 0; i < people.length; i++) { 
   			 names.push(people[i].DisplayText); 
		}
	});
	fd.field('Original_x0020_Source_x0020_of_x').value(sourceOfLeadLookupText + ' - ' + referringEmployeeName);
} 
As I say I just need the user name in plain text...

Just so you know this is a single choice people picker field, if that makes a difference.

Thanks

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 Sep 2017

Hello, Tony!
Let's try some tests from the console then. I want you to enter these three commands one by one and tell me the results:

Code: Select all

fd.field("Referring_x0020_Employee_x0020_N").value();
fd.field("Referring_x0020_Employee_x0020_N").value()[0];
fd.field("Referring_x0020_Employee_x0020_N").value()[0].DisplayText;

// and possibly this one, in case the user is not stored in an array:
fd.field("Referring_x0020_Employee_x0020_N").value().DisplayText;
With the following commands, I get the following result from the single selection People Picker:
People Picker Console.png
People Picker Console.png (10.5 KiB) Viewed 1486 times
You can also hide personal information, I just want to see if you can get text value from the object this way or not. Finally, you can open the object and take a look at its properties from the console, maybe you can find the right one for you, in case it's not DisplayText.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests