How to use "Name" value (FullName) from User List rather than "Value" (Email Address)?
I have a user list configured in a form (internal name is systemowner5), where the user selects Name (Full Name), and the Value is equal to the email address, so that I can ultimately email the user selected. In addition to emailing the user, I also want to display their full name in the email, but when I enter the systemowner5 form field, it displays the email address. Is there a way I can display the Name (FullName) instead? I have included pics. Thank you!!
-
Since the User List is essentially a drop-down Name/Value field, only the value is going to be available in your schema. To do what you want to do, you will need to define an additional hidden text-box field on your form to contain the Full Name. Then you will need to create a little JavaScript code to pull the selected Name from the drop-down and populate your hidden Full Name field.
So let's say you define a hidden text-box called SystemOwnerName. You will then need to add the following JavaScript to your form:
function getSystemOwnerName()
{
var dropDownSelectName = dropdownDisplayValue("systemowner5");
setFieldNameObjectValue("SystemOwnerName",dropDownSelectName);
}function dropdownDisplayValue(dropdownFieldName)
{
var dropDownSelectObj = getFieldNameObject(dropdownFieldName);
var dropDownSelect = dropDownSelectObj.find("option:selected").text();
return dropDownSelect;
}function getFieldNameObject(fieldName)
{
var fieldObj;
eFormHelper.getField({ fieldId: fieldName }, function (result) { fieldObj = result.data; });
return fieldObj;
}function setFieldNameObjectValue(fieldName, val)
{
eFormHelper.setFieldValue({ fieldId: fieldName, value: val });
}Then on your User-List control, go to the Advanced tab and tell it that you want to execute the JavaScript function getSystemOwnerName() on the "Change" event:
This will then populate the SystemOwnerName field with the Full Name selected from the User-List. You can then use the SystemOwnerName field in your email.
The JavaScript I displayed above could probably be condensed by combining some of the functions. I just copied this from an existing application I have where I call those various functions for different reasons.
-
Hi Valerie,
The solution provided by Loren is right way (Script + User list control change event).
Also, I have same solution with script only approach (Below scripts are self-explanatory and easy to maintain )
/* Helper methods - (below 2 methods never changes) */
function Set(name, value) { eFormHelper.setFieldValue({fieldId: name, value: value}); }
function GetControl(name) { var r; eFormHelper.getField({ fieldId: name }, function (res) { r = res.data; }); return r; }
$(document).on('change', '#systemowner5', function(e) {
var userListControl = GetControl('systemowner5'); //Gets your userlist control
var selectedFullName = $(userListControl).find("option:selected").text(); //Gets selected fullname
Set('systemowner5FullName', selectedFullName); //Sets fullname to mentioned control
});Hope this helps!
-
Got it! Thanks for showing me that!!
{
var dropDownSelectName = dropdownDisplayValue("systemowner5");
setFieldNameObjectValue("SystemOwnerName",dropDownSelectName);
}
function dropdownDisplayValue(dropdownFieldName)
{
var dropDownSelectObj = getFieldNameObject(dropdownFieldName);
var dropDownSelect = dropDownSelectObj.find("option:selected").text();
return dropDownSelect;
}
function getFieldNameObject(fieldName)
{
var fieldObj;
eFormHelper.getField({ fieldId: fieldName }, function (result) { fieldObj = result.data; });
return fieldObj;
}
function setFieldNameObjectValue(fieldName, val)
{
eFormHelper.setFieldValue({ fieldId: fieldName, value: val });
}
Please sign in to leave a comment.
Comments
7 comments