Gunjan Kiratkar
Kilo Patron
Kilo Patron

Use Case  1:-

On clicking a button on the requested item form Create the custom PDF document of the Requested Item form fields and Attached that to the current RITM record.

Solution:-

Steps:-

1. Create one email template in the ‘sysevent_email_template’ table.

find_real_file.png

Fig. Email Template

2. Create the UI action on the ‘sc_req_item’ table and past the below code:-  

var getTemplate = new GlideRecord("sysevent_email_template");
getTemplate.addQuery("sys_id", "57c93b6d2f2201501a5cf3ecf699b631");
getTemplate.query();
if (getTemplate.next()) {
var temp = getTemplate.message_html;
var updatedHTML = temp.replace('ExampleReqBy', current.getDisplayValue('u_requested_by'));
updatedHTML = updatedHTML.replace('ExampleReqFor', current.getDisplayValue('requested_for'));
updatedHTML = updatedHTML.replace('ExampleAssgTo', current.getDisplayValue('assigned_to'));
updatedHTML = updatedHTML.replace('ExampleAssgGroup', current.getDisplayValue('assignment_group'));
updatedHTML = updatedHTML.replace('ExampleShortDes', current.getDisplayValue('short_description'));
updatedHTML = updatedHTML.replace('ManagerOfAssigmentGroup', current.getDisplayValue('assignment_group.manager'));
}
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.convertToPDF(updatedHTML, "sc_req_item", current.sys_id, "Excel Template");

 

Use Case 2:-

When RITM is created and the Assignment Group of RITM is not empty then send the notification to the Assignment Group Members with the RITM custom document and attached the same document to the Current RITM.

Solution:-

Steps:-

1. Create one email template in the ‘sysevent_email_template’ table.

find_real_file.png

Fig. Email Template

2. Write down the email script as below:-   

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

// Add your code here
var getTemplate = new GlideRecord("sysevent_email_template");
getTemplate.addQuery("sys_id", "57c93b6d2f2201501a5cf3ecf699b631");
getTemplate.query();
if (getTemplate.next()) {
var temp = getTemplate.message_html;
var updatedHTML = temp.replace('ExampleReqBy', current.getDisplayValue('u_requested_by'));
updatedHTML = updatedHTML.replace('ExampleReqFor', current.getDisplayValue('requested_for'));
updatedHTML = updatedHTML.replace('ExampleAssgTo', current.getDisplayValue('assigned_to'));
updatedHTML = updatedHTML.replace('ExampleAssgGroup', current.getDisplayValue('assignment_group'));
updatedHTML = updatedHTML.replace('ExampleShortDes', current.getDisplayValue('short_description'));
updatedHTML = updatedHTML.replace('ManagerOfAssigmentGroup', current.getDisplayValue('assignment_group.manager'));
}
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.convertToPDF(updatedHTML, "sc_req_item", current.sys_id, "Excel Template");

var attach = new GlideRecord('sys_attachment');
attach.orderByDesc('sys_created_on');
attach.addQuery('file_name', 'Excel Template.pdf');
attach.query();
if (attach.next()) {
template.print('<a href="' + gs.generateURL(attach.getTableName(), attach.sys_id) + '">' + "Excel Template" + '</a>');
}

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

3. Create the notification and call the email script in it as below:-

find_real_file.png

Fig. Email Notification

 

Final Output Document:-

 find_real_file.png

Fig. RITM Custom PDF Document

 Email Notification Output:-

find_real_file.png

Fig. Email Output

 If you don't want to go through all the steps then find below attached update set file.

 

Please mark my article as helpful and bookmark it for future use.

Regards,

Gunjan Kiratkar

Consultant - ServiceNow, Cloudaction

Rising Star 2022

Comments
Ramesh Raju
Tera Contributor

Great work Gunjan, Its very helpful.

I learned a new thing with your article....

Tina Kumar
Kilo Contributor

Nice Usecase. I learned a new thing today.

Thanks.

Version history
Last update:
‎03-30-2022 08:03 AM
Updated by: