Email address in reference field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2015 03:33 PM
Let's say I have a custom field called email Address which reference to User Table (sys_user). Now, I want that on selecting any record in reference table, email address of the user should select in the email address field, right now by default it is accepting user name.
Also, I don't want to remove the columns from the list layout. Any other solution I have for this.?
I also tried adding attributes method but that is also not working. I don;t know why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2015 04:36 PM
Hi Chandresh,
The display field for a reference is set at the table level, for the table being referenced.
If you need to show the e-mail address on the form, you can add a Derived Field and display it just under the reference field.
If you do this, you will probably want to add the email address as one of the reference field lookup columns, and display that to the user when they are typing in the reference field. There is a lot of information about how to do that here in the wiki:
https://wiki.servicenow.com/index.php?title=Auto-Complete_for_Reference_Fields
For your case, you will probably want to edit the dictionary entry for your custom reference field and set attributes like the following:
ref_auto_completer=AJAXTableCompleter,ref_ac_columns=email,ref_ac_order_by=email
That will make the reference-completer look like this:
When selected, the derived field displays automatically:
You may want to add a UI Policy to set Caller.email (in the example above) to read-only. It's likely that your users already wont have write-access to that field, so it will show read-only to them, but the UI Policy makes it explicit.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2015 05:24 AM
Hi Cory,
Derived fields will not work here as we have a custom field in custom application. So we cannot change the label here. Try to do the dictionary override also but that option is not available and Attributes method I have already tried but no luck.
Moreover I need to populate other fields of user on the basis of email id.So I really need a solution to populate email id in a field from sys_user reference table without changing the attribute present in OOB table.
Do I have any other option?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2015 10:46 AM
Hi Chandresh,
You can't force the Reference field to act the way you want it to. You can add a custom field called "email address" (or similar) and auto-populate it with the email address of the user when the reference-field changes. Do this with an onChange script on the reference field. Something like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//when user changes, set our custom email field (which has our custom label)
g_form.getReference(("user"), function(ref) {
g_form.setValue("email_field", ref.email);
});
}
This way you get your field onto the form with your label, and take advantage fo the reference-picker for search and validation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2015 05:05 AM
Hi Cory,
I understand what you are saying here, but my requirement is not set Email based on Caller. I am planning to write an onChange client script which will run on change on email id field and set the email address of the user name present in the email address.I guess, this is the only option left to achieve my requirement.