Create a incident record, when incident state changes to "Resolved." , Export a PDF of resolved incident automatically & attach a attachment in Email notification Send Notification to the caller with attached attachment of incident record.

Rushikesh5
Giga Guru

Hi, I have this requirement can anyone help me with this i.e. how to do it

  • Create an incident record, when incident state changes to "Resolved." ,
  • Export a PDF of resolved incident automatically & attach a attachment in Email notification.
  • Send Notification to the caller with attached attachment of incident record.

Thanks

1 ACCEPTED SOLUTION

@Rushikesh 

Glad to know that my approach worked.

Please mark my response as correct and helpful to close the thread.

Regards
Ankur

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

View solution in original post

18 REPLIES 18

Hi,

These are the steps of BR:

Advanced is true

1. Table used for BR is Incident

2. When to run: After insert or update(both are true)

3. Condition: Incident_state is resolved

4. Script of BR as per that link

 

(function executeRule(current, previous /*null when async*/) {

var basicAuthProfileSysID = gs.getProperty('com.customer.pdf.authprofile');

generateAndStoreAttachment('incident', '12345678900000000000', 'Default', current.sys_class_name, current.sys_id,'Incident_Export.pdf', basicAuthProfileSysID);

function generateAndStoreAttachment( pdfTable, pdfSysID, pdfView, attachToTable, attachToSysID, fileName, authProfileSysID ) {

var r = new sn_ws.RESTMessageV2();

r.setHttpMethod('get');

r.setEndpoint('https://'+gs.getProperty('instance_name')+'.service-now.com/' + pdfTable + '.do?PDF&sys_id=' + pdfSysID + '&sysparm_view=' + pdfView);

r.setAuthenticationProfile('basic', authProfileSysID);

r.saveResponseBodyAsAttachment(attachToTable, attachToSysID, fileName);

var response = r.execute();

//response.getStatusCode();


gs.eventQueue('inc_event', current, current.caller_id);


}


})(current, previous);

 

If something is not right please do let me know

 

Regards,

Rushikesh

Hi,

Okay so did you create correct auth profile property?

Did you add logs to check what response came from REST Message?

Can you share what debugging you have performed?

Regards
Ankur

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

Hi,

I am new to ServiceNow can you please explain to me about the auth profile property i.e how to do it 

 

Regards,

Rushikesh

Seems your other 2 colleagues are also having same requirement and have posted questions

https://community.servicenow.com/community?id=community_question&sys_id=670b79ea1b0a0590be4955fa234b...

https://community.servicenow.com/community?id=community_question&sys_id=658e159a1b4e019086b3ece6b04bcb2f

You 3 guys can collaborate together and debug it since all of you are following same approach.

Approach I shared there has worked for me in past.

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

Regards
Ankur

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

Hi,

(function executeRule(current, previous /*null when async*/ ) {

    var rm = new sn_ws.RESTMessageV2();
    rm.setHttpMethod('GET');
    var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
    rm.setEndpoint(url);
    // Create new properties and save user id and password of an admin account
    rm.setBasicAuth('admin', 'your password');
    rm.saveResponseBodyAsAttachment(current.getTableName(), current.getUniqueValue(), current.number + ".pdf");
    var response = rm.execute();

})(current, previous);

I used this script and now the email is triggered but the attachment is not there

 

Regards,

Rushikesh