Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Attach PDF to email notification

Community Alums
Not applicable

Hello,

Does anyone know how I would go about creating an email notification so when the record closes, it attaches a PDF of that record in the email? 

Thanks in advance!

6 REPLIES 6

Mallidi Suma
Tera Guru

Hi @Community Alums ,

 

You can achieve the above requirement by following the below steps:-

My use case is sending the attachment of the incident Record to the caller once the Incident is closed.

Step 1:-

Go to "sys_auth_profile_basic.LIST"  and insert one Basic Auth Configuration. Copy the Sysid of this record(We will use this in Step 3).

 

Screenshot 2023-05-20 at 12.52.14 PM.png

 

For more information please find the docs "https://docs.servicenow.com/bundle/utah-api-reference/page/integrate/outbound-rest/task/t_CreateABasicAuthProfile.html"

 

Step 2:-

created an event in the event Registry

 

Screenshot 2023-05-20 at 12.57.34 PM.png

 

Step 3:-

Create an update Async or after-business rule and add the below code:-

Code:-

(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var RecordSysID = current.sys_id;
var RecordTable = current.sys_class_name;
var AttachPDFView = '';
var TargetFileName = 'IncidentPDF'; //Your target Attachment Name
var AuthProfileSysID = 'f2df706347b2a110ea6d8c38c26d435d'; // Copy and paste the sysID of above created Auth Profile
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod('get');
r.setEndpoint('https://' + gs.getProperty('instance_name') + '.service-now.com/' + RecordTable + '.do?PDF&sys_id=' + RecordSysID + '&sysparm_view=' + AttachPDFView);
r.setAuthenticationProfile('basic', AuthProfileSysID);
r.saveResponseBodyAsAttachment(RecordTable, RecordSysID, TargetFileName);
var response = r.execute();
//gs.log(response.getStatusCode());
gs.eventQueue('send.notification.with.pdf', current, current.caller_id, fileName);
//Triggering the event which I created in Step 2
})(current, previous);
 
Step 4:-
Created a notification with a trigger of the event fired and added my step 3 created event. While configuring the notification check include the attachments check box.
 
Screenshot 2023-05-20 at 1.00.28 PM.png
 
Screenshot 2023-05-20 at 1.00.52 PM.png

Screenshot 2023-05-20 at 1.01.30 PM.png

Please mark my answer as helpful and accept it as a solution, if it helps !!

 

Thanks & Regards,

Suma.

Community Alums
Not applicable

Hello @Community Alums ,

 

For this, you can simply use this share project, "Export Record - Flow Action".

In flow designer :

  • Mention trigger conditions according to your requirements.
  • Then use the action "Export a Record".
  • Then select the action "Send Email.

 

@Community Alums , Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank you!

Community Alums
Not applicable

Hi just tried to do this but I cant find the action is it known by any other name?

Community Alums
Not applicable

Hello @Community Alums ,

 

First u need to go to this share project "Export Record - Flow Action". (https://developer.servicenow.com/connect.do#!/share/contents/8236087_export_record_flow_action?t=PRODUCT_DETAILS). SS:

 

Khushbookabra_0-1684654858080.png

 

And then click on download button (for to retrieve the update set).

Khushbookabra_2-1684655303197.png

 

 

Then commit the update set "Export Record" in your instance.

Khushbookabra_1-1684655126011.png

 

 

Then go to flow designer u will find this flow action "Export a Record".

 

Khushbookabra_3-1684655396011.png

 

Thanks.