- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 03:34 AM
Hi all,
(I'm new to ServiceNow)
I am looking to create an email notification, which sends an email to HR when we are notified a user is leaving the company.
I have an event in place, and the email notification is triggered and sent.
However, the issue I have is with the content of the email. When a user completes an online form within our portal, I have a reference field named "leaver". I need to capture this value, and include it within the email to HR. I thought it would show within the "fields" group, but it doesn't. Can I make it appear in there?
All help appreciated.
Ryan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 04:03 AM
Hi Ryan,
I assume 'leaver' field is on online catalog item or record producer. Variable created on the catalog item or record producer are not accessible directly on the email. To pull value of variable in the email template, you will have to write below code.
<mail_script>template.print(current.variables.leaver.getDisplayValue())</mail_script>
Please mark answer as Helpful/Correct, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 04:03 AM
Hi Ryan,
I assume 'leaver' field is on online catalog item or record producer. Variable created on the catalog item or record producer are not accessible directly on the email. To pull value of variable in the email template, you will have to write below code.
<mail_script>template.print(current.variables.leaver.getDisplayValue())</mail_script>
Please mark answer as Helpful/Correct, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 04:05 AM
Hi Ryan,
I had to write a script to add this to a notification I required for a similar reason. Add this code to your notification:
<mail_script>
printVars();
function printVars() {
// Print list of catalog variables into email, written by Adam Domanski
template.print('<b>Request Details</b>\n');
var cv = new GlideRecord('sc_item_option_mtom');
cv.addQuery('request_item', current.sysapproval);
cv.addQuery('sc_item_option.item_option_new.type', 'IN', '1, 10, 16, 18, 2, 21, 22, 3, 4, 5, 6, 7, 8, 9'); // '2, 6');
cv.addNotNullQuery('sc_item_option.value');
cv.orderBy('sc_item_option.order');
cv.addQuery('sc_item_option.value', '!=', '0');
cv.query();
while(cv.next()) {
template.print('\n' + cv.sc_item_option.item_option_new.question_text + ':\t<b>' + cv.sc_item_option.value + '</b>');
}
</mail_script>
You can play with lines 6-10 to change the query of which fields from the Catalog Item you are using, let me know if you need help with that. Line 13 formats the output of text into the notification, which can also be adjusted if required.
Cheers, Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 05:06 AM
Hi Adam,
The solution proposed by "solutioner now" does output the variable I require, into the text of the email.
.
I have used your code in the email, and there is no output. All I require is the user name (and account username), to be visible in the email. I would also like to add that into the subject field of the email, yet I can't run a <mail_script> in there. I notice you create a GlideRecord object with a parameter as 'sc_item_option_motm' - what is this?
I would like to be able to use the code you've supplied, as it looks like something that would benefit me going forwards, as more and more notifications are required.
Much appreciated,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2014 05:16 AM
Hi Ryan,
Happy to see that the solution got you a value !!
Further to the Code suggested by adam could also be helpful if you have requirement for querying the table for more information and use that in the email.
Request you to mark answer as Helpful or Correct, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/