- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 11:07 AM
Hi Team.
I'm working with the Email [sys_email] and the Incident tables.
I need to display the email address that appears in the sys_email.user field in a custom reference field that I created in the Incident table. This custom field only displays when the Caller field in the Incident form is populated with "Guest".
Here is what I have done so far.
I created a new field on the Incident form called Guest Email Address, as a Reference type. Since the Email [sys_email] table was not listed in the Table of Reference field, I used TASK. I then created a UI Policy to display the new field only when the Caller is Guest. I returned to the Incident form, typed Guest into the Caller field to display the new field and it displayed. I accessed the field's Dictionary and under the Reference Specification tab, I changed the table from TASK to Email [sys_email]. Then, selected "User" as the Reference field for the new Guest Email Address field.
After completing these steps, I tested by sending an email to the instance from a non-business email address. The email arrive and an INC ticket was created with Caller = Guest and the Guest Email Address field was visible, but blank.
I went into the System Mailboxes / Inbound / Received folder of ServiceNow and confirmed that the "User" field was populated with the email address.
I have very little scripting knowledge. What can I do to make the custom reference field display the email address from the User field in the sys_email table?
Thank you in advance for any suggestions/recommendations.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 04:58 PM
Hi,
Sorry, I forgot some of the syntax when using the "email" object in Inbound Action scripts. We don't actually need the if-statement either, so literally all we need to do is set the incident record (referred to as "current") custom Guest Email Address field to the email object's "from" property, which is defined as the FROM in the message headers, if it doesn't match to a user in the system. This code should work:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Set the Guest Email Address field to the FROM value in the message headers:
current.u_guest_email_address = email.from;
})(current, event, email, logger, classifier);
Again, that assumes the database name of your Guest Email Address field is "u_guest_email_address". If you're not sure, go to the Incident Table definition or dictionary and double-check.
More info about using the "email" object in Inbound Action scripts here:
https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/notification/reference/r_AccessingEmailObjsWithVars.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 11:53 AM
Incidents do not have a direct reference to the inbound email that created them, so this is going to need to be done via script.
I would suggest first changing your Guest Email Address field to be a plain string field (and make it read only), then adding the following line to the "Create Incident" Inbound Email Action (you can find this under System Policy > Email > Inbound Actions):
if(email.user_id=="") current.u_guest_email_address = email.user;
This assumes the field name of your Guest Email Address field is "u_guest_email_address". email.user_id is the reference to the user record, if it exists, but should be nothing for a guest user, in which case email.user will be the from address.
One more thing to note... if not already done, you can customize the Activity Log on the Incident Form to show sent/received emails. This will show the entirety of the source email, including sender's email address, as the very first entry in the Activity Log on the Incident form (it shows slightly different from field changes and work note / comment additions - emails you can click to expand to see full content).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 12:53 PM
Thanks Ben. Greatly appreciate your information. I changed the Guest Email Address field type from Reference to String. It was already as Read-only. Then added the script to the Create Incident Inbound Email Action, saved it, tested by sending an email from a non-business email address and the Guest Email Address field did not populate. Is it that the script is the only line on the Script field? Here is what I have.
Thanks again!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 04:58 PM
Hi,
Sorry, I forgot some of the syntax when using the "email" object in Inbound Action scripts. We don't actually need the if-statement either, so literally all we need to do is set the incident record (referred to as "current") custom Guest Email Address field to the email object's "from" property, which is defined as the FROM in the message headers, if it doesn't match to a user in the system. This code should work:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Set the Guest Email Address field to the FROM value in the message headers:
current.u_guest_email_address = email.from;
})(current, event, email, logger, classifier);
Again, that assumes the database name of your Guest Email Address field is "u_guest_email_address". If you're not sure, go to the Incident Table definition or dictionary and double-check.
More info about using the "email" object in Inbound Action scripts here:
https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/notification/reference/r_AccessingEmailObjsWithVars.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 07:13 AM
Good morning, Ben.
Thanks so much for your information. I replaced the If statement with your new code and it worked!
Greatly appreciate your time and help.
Joy