Text Value of People Picker
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: -
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
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 I would like returned is - Employee Referral - Employee Name
Help appreciated please.
Thanks
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 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
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 -
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
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);
}
Just so you know this is a single choice people picker field, if that makes a difference.
Thanks
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 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:
With the following commands, I get the following result from the single selection People Picker:
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.
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;
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 5 guests