Send Offer letter pdf attachment in notification

JohnnySnow
Kilo Sage

Hi Team,

 

In our flow we have the requirement of sending the offer letter in email to the employee. High level process is as follows:

1. Manager raise request.

2. Approver approves

3. HR team gets an HR task to populate few fields (this we are doing through Employee forms), these fields need to be put into the offer letter.

4. Once 3 step is over, a notification & a task is generated for the employee (a task of e-signature type). 

 

Now  post step3 we want to generate the offer letter pdf and send this to the employee. 

 

I'm not sure how to achieve it.

 

One way, I figured could be to use 

new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);

to generate the pdf, but not sure how to call this in the flow designer.

 

If there are better ways to achieve this please do let me know. 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.
10 REPLIES 10

Community Alums
Not applicable

Hello @JohnnySnow ,

 

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". (You will get the Record Export (Name of Update Set) of this "Export a Record" (Action) from the above-mentioned share project)
  • Then select the action "Send Email."

Steps:

First u need to go to this share project "Export Record - Flow Action".

URL : (https://developer.servicenow.com/connect.do#!/share/contents/8236087_export_record_flow_action?t=PRO...). SS:

 

Khushbookabra_0-1687803358443.png

 

 

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

Khushbookabra_1-1687803358450.png

 

 

 

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

Khushbookabra_2-1687803358561.png

 

 

 

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

 

Khushbookabra_3-1687803358451.png

 

@JohnnySnowPlease mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank you!

 

JohnnySnow
Kilo Sage

Hi Team,

 

 

Just an update, I have made below progress so far.. I tried using the OOTB generate pdf but I believe I was encountering lot of cross scope issues.

 

Instead I have created a custom script action in Flow designer and gave cross scope access as shown below.

 

Application restricted caller access:

JohnnySnow_4-1688346758518.png

Script Action Code:

(function execute(inputs, outputs) {

  
/*
templateSysID - Sys ID of the HTML Template.
generatedPdfName - Name of the PDF that will be generated.
tabName - Name of the table.
caseID -  Sys ID of the case/task where the pdf has to be attached.
*/

var templateSysID = inputs['templateID'];
var generatedPdfName = inputs['pdfname']; 
var tabName = inputs['targetTableName'];
var caseID =inputs['targetRecordID'];

//Fetch the HTML Template Record
var htmlTemplateGr = new GlideRecord("sn_doc_html_template");
htmlTemplateGr.get(templateSysID);
 
//Fetch the Case Record
var grTable = new GlideRecord(tabName);
grTable.get(caseID);

  
/*
body - Captures the data from html_script_body of the HTML template.
tableName - Table name assigned to the HTML template.
tableID - Sys ID of the table.
signatureData - Looks up the participants mentioned in HTML Template.
*/

  
var body = htmlTemplateGr.getValue('html_script_body');
var tableName = 'sn_hr_le_case'; 
var tableID = grTable.getUniqueValue();
var signatureData='';

  gs.info(htmlTemplateGr.getRecordClassName());
  
var parsedhtmlBody = new sn_doc.HtmlTemplateUtils().getPrefilledBody(body, tableName, tableID, signatureData);

params = {};
params.htmlBody = parsedhtmlBody;
params.targetTable = tabName;
params.targetSysId = grTable.getUniqueValue();
params.generatedPdfName = generatedPdfName;
params.htmlTemplateGr = htmlTemplateGr; 


//Attach the PDF to the case record
outputs.generate_pdf_sys_id = new sn_doc.HtmlTemplateUtils().generateDocumentAsAttachment(params);
  
  
})(inputs, outputs);

 

 

With this I'm able to generate pdf and attach it to case, I'm still working on attaching the same to task (instead of case) and sending this as an attachment to the case.

Will keep you guys posted.

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

@JohnnySnow 

in your script why not query HR Task table instead of HR case?

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

I had tried that the attachment gets attached fine, but the contents of the pdf was always 'Undefined'. 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

Community Alums
Not applicable

@JohnnySnow , Have you check this utility : "Export Record - Flow Action"?.