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

@dmahendran 

share your script and screenshots.

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

Attaching the Snip here.

Hi @dmahendran ,

 

Your notification is on the Requested Item table, not on the Approval table, correct?

If so then please check my response.

 

Regards,

Robert

@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

Robert H
Mega Sage

Hello @dmahendran ,

 

Please create a new Email Script that adds the additional details for the special Catalog Item, for example:

Name: more_info_for_special_cat_item

Script:

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

	var specialCatItem = 'e1be6dcb4f7b4200086eeed18110c74c';
    if (current.getValue('cat_item') == specialCatItem) {
        // additional details go here, for example:
        template.print(current.getValue('due_date'));
    }

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

 

Then add a reference to this script in the Message text of your Notification, at the position where the additional details shall appear:

 

other content
...
${mail_script:more_info_for_special_cat_item}
...
other content

 

Regards,

Robert