Notification Script: email notification that pulls 'caller' first name and subject line info

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 10:09 AM
Greetings Folks.
I am a newish admin and trying to build notifications, I am not a script writer, but I have the challenge of trying to build a script to send a notification when their e-mail has been received...
I am wanting to have a notification that has a format like:
“Greetings (Caller first name)
Your message {short description} has been received. We will respond to you as soon as possible.”
I’m not sure how to script the opening and pull just the callers first name.
I started building this for an e-mail script:
But from what I’m learning I know I need to set some kind of variable to grab the caller’s first name. I’m not quite sure how that would look in an e-mail script. I am also not sure how to structure line 4 so as to insert the subject line {short description?} between the "Your message" and the remainder of the sentence...
I found this in the Servicenow community: https://community.servicenow.com/community?id=community_question&sys_id=fe14cfe5dbd8dbc01dcaf3231f96...
<mail_script>
var userName = current.caller.first_name.toString().charAt(0).toUpperCase() + current.caller.first_name.toString().slice(1);
template.print("Hello " + userName + "<br />");
</mail_script>
But it’s 4 years old, and I don’t know if there’s a better way to do it, or how to incorporate that mail script into what I’m trying to do.
Any suggestions?
Cheers
A.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 10:22 AM
Does your email script and notification print out anything successfully yet or is the entire thing not working? If it's mostly working and you just need to get the first name and subject you can print that within your mail script like this...
template.print("Greetings " + current.caller_id.first_name + ",");
template.print("Your message " + current.short_description + " has been received. We will respond to you as soon as possible.");
The reason this works is that you almost always have the 'current' record object passed in to the email notification to be used. Because of that, you can simply dot-walk to whatever you want to use.
You could also do this without a mail script directly in the email notification without any real scripting (although you may choose a mail script if you've got other pieces that require it). Again, the 'current' object presents you with variables that you can use with the correct syntax to include.
Greetings ${caller_id.first_name},
Your message ${short_description} has been received. We will respond to you as soon as possible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 10:43 AM
Hi Mark
I appreciate the feedback!
So if I understand you correctly (and I'm not saying I do) Then I can either create an e-mail script with the format of your first example which will look like this when I'm done:
(function runMailScript(current, template, email, email_action, event) {
template.print('<p><font size="5" color="#808080" face="helvetica"><strong>');
template.print("Greetings" + current.caller_id.first_name +",");
template.print("Your message" + current.short_description +" has been received. We will respond to you as soon as possible."));
template.print('</strong></font></p>');
})(current, template, email, email_action, event);
Or I could just create an e-mail notification using the format of your second example?
If my understanding is correct that is intriguing, but in the end I am not sure how I would manage the rest in that format such as including our Help Desk signature.
I'm going to test your first example and see what happens.
Cheers
A.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 10:55 AM
Your assumptions are correct. Let me know how it works!