Email Notifiacation

dmahendran
Tera Contributor

Hello Guys,

 

I have a requirement where, if an approval is rejected for a specific catalog item, I need to include some additional details in the "Closed Complete" notification that is sent from the Request table. However, this notification is global and used for all catalog items. I want to update it only for this particular catalog item without impacting any others. Can someone help me achieve this?

1 ACCEPTED SOLUTION

@dmahendran 

if your notification is on sc_request then script I shared is correct but you added these lines again

(function runMailScript(current, template, email, email_action, event) {

})(current, template, email, email_action, event);

so just keep this below code within the email script

    var rec = new GlideRecord('sc_req_item');
    rec.addQuery('request', current.sys_id);
    rec.addQuery('cat_item.name', 'Your Item Name');
    rec.query();
    if (rec.hasNext()) {
        template.print('your content here');
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@dmahendran 

then separate it out

1) update the OOTB email notification so that it doesn't trigger for that specific catalog item, use the advanced notification condition and use script to check this

var rec = new GlideRecord('sc_req_item');
		rec.addQuery('sys_id', current.sysapproval);
		rec.addQuery('cat_item.name', 'Your Item Name');
		rec.query();
		answer = !rec.hasNext(); // don't trigger OOTB if it's your item

2) create a new notification on sysapproval_approver which triggers only for your specific catalog item, use script in advanced notification condition script

var rec = new GlideRecord('sc_req_item');
		rec.addQuery('sys_id', current.sysapproval);
		rec.addQuery('cat_item.name', 'Your Item Name');
		rec.query();
		answer = rec.hasNext(); // trigger for your item only

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar 

My requirement is to trigger the standard out-of-the-box "Closed Complete" email notification as it normally works. However, for one specific catalog item, I need to append some additional notes at the bottom of the email—without impacting how the notification behaves for other catalog items.  

@dmahendran 

then create a email script and add that in the OOTB email notification body

in the email script check close completion is for which catalog item and then only include the email content

Something like this in email script

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var rec = new GlideRecord('sc_req_item');
    rec.addQuery('request', current.sys_id);
    rec.addQuery('cat_item.name', 'Your Item Name');
    rec.query();
    if (rec.hasNext()) {
        template.print('your content here');
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Still I'm not able to find any message Contents in the OOTB Email Body.