- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:24 AM
Hi Team ,
Am trying to add variable from email script to email notification dynamically :
Below is my code for email script :name:Test Inc
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var number = current.incident;
var getInc = new GlideRecord('incident');
getInc.addQuery("sys_id", number);
getInc.query();
if (getInc.next()) {
gs.info('enter in email script');
email.addVariable('Inc Number', 'true');
} else {
email.addVariable('Inc Number', 'false');
}
})(current, template, email, email_action, event);
Below is my notifications code (message HTML):
State: ${state}
Priority: ${priority}
Inc Number : ${mail_script:Test Inc}
I can see the log enter in email script .
am not getting the Inc Number value in notifications
State: open
Priority: 2.high
Inc Number :
Please guide me the best practices .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:39 AM
Rather than email.addVariable, you can just do template.print(). When you reference the mail script it will print what you told it to do in the mail script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:50 AM
@String : "template.print" is used to print the information from the email script to the notification. In this case, replace your [email.addVariable('Inc Number', 'true')] statement with [template.print(number)] which prints the incident number.
If it's still not working, please update your email script name to Test_Inc in both the email script and in your notification. The system treats Test Inc. as different words and might not work as expected.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:53 AM
Hello @Kristen Ankeny ,
Please give a try to the modified script below and let me know how it works for you.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var number = current.incident;
var getInc = new GlideRecord('incident');
getInc.addQuery("sys_id", number);
getInc.query();
if (getInc.next()) {
gs.info('Entered in email script');
// Use template.print() to directly print the value in the email body
template.print(getInc.number);
} else {
// Handle the case where the incident record is not found
gs.info('Incident record not found');
template.print('N/A');
}
})(current, template, email, email_action, event);
And in your email notification template:
State: ${state}
Priority: ${priority}
Inc Number: ${mail_script:Test Inc}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:39 AM
Rather than email.addVariable, you can just do template.print(). When you reference the mail script it will print what you told it to do in the mail script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:50 AM
@String : "template.print" is used to print the information from the email script to the notification. In this case, replace your [email.addVariable('Inc Number', 'true')] statement with [template.print(number)] which prints the incident number.
If it's still not working, please update your email script name to Test_Inc in both the email script and in your notification. The system treats Test Inc. as different words and might not work as expected.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:53 AM
Hello @Kristen Ankeny ,
Please give a try to the modified script below and let me know how it works for you.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var number = current.incident;
var getInc = new GlideRecord('incident');
getInc.addQuery("sys_id", number);
getInc.query();
if (getInc.next()) {
gs.info('Entered in email script');
// Use template.print() to directly print the value in the email body
template.print(getInc.number);
} else {
// Handle the case where the incident record is not found
gs.info('Incident record not found');
template.print('N/A');
}
})(current, template, email, email_action, event);
And in your email notification template:
State: ${state}
Priority: ${priority}
Inc Number: ${mail_script:Test Inc}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket