Email script & Notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 03:15 AM
My requirement is in the notification if i have 5 catalog items in my name all the catalog items name should be populated in the email body notication.
I have created the notification from the sys_user table and it is triggering by using event that is triggering emails as expected but i m not able to populate catalog items name in my email notification.
I have created an email script to retrieve and list the catalog item names and included that script in the notification but it is not working
Email script that i have created:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 03:29 AM
Hi @rahul122 ,
update your notification email script as below
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var list = '';
var catGr = new GlideRecord('sc_cat_item');
catGr.addActiveQuery();
catGr.addQuery('owner', current.getValue('sys_id'));
catGr.query();
while (catGr.next()) {
list += '-' + catGr.getDisplayName('name') + '\n';
}
template.print('<div>' + list + '</div>');
})(current, template, email, email_action, event);
and add this in the notification body
${mail_script:userCatalogNames}
Note: I have give email script name as userCatalogNames r replace it with your email script name
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 03:50 AM - edited 06-26-2025 03:50 AM
Hi @Chaitanya ILCR thank you for your reply ,
I have tried your script now it is returning only as 'name' , it is not showing name of the catalog item's.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 03:52 AM - edited 06-26-2025 03:57 AM
Hi @rahul122 ,
update as this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var list = '';
var catGr = new GlideRecord('sc_cat_item');
catGr.addActiveQuery();
catGr.addQuery('owner', current.getValue('sys_id'));
catGr.query();
while (catGr.next()) {
template.print('<p> - ' + catGr.getDisplayValue() + '</p>');
}
})(current, template, email, email_action, event);
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 03:45 AM
Hi @rahul122,
You can use array to achieve it, and print the Catalog names. Below code will have Catalog item names listed one by one. Be sure to call email script in notification with syntax - ${mail_script:<email_script_name>}
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var itemNames = [];
// Query the catalog items (sc_cat_item) where the current user is the owner
var itemGR = new GlideRecord('sc_cat_item');
itemGR.addQuery('owner', current.sys_id);
itemGR.query();
while (itemGR.next()) {
itemNames.push(itemGR.getValue('name'));
}
for (i in itemNames) {
template.print(itemNames[i] + '<br>');
}
})(current, template, email, email_action, event);