Generate PDF Document Action in Flow Designer

Austin_Brunet
Tera Expert

Hey everyone!

 

I am looking for a way to generate a PDF in flow designer with the new "Generate PDF Document" action in flow designer. I have created the document template, but not sure how the action works or what information needs to be placed into each of the fields.

 

The request is based on an SCTASK, the PDF can be generated where the tech only has to type in the information needed (4 boxes on the PDF). I cannot show the entire PDF, but here are 3 of the 4 boxes that they would like to be populated. The 4th box is the date that this is generated.

 

Can anyone help?

 

Thanks in advance!

 

Austin Brunet

2 ACCEPTED SOLUTIONS

@Austin_Brunet I did some search and found that the Generate PDF Document action only works with HR Templates. Unfortunately, this action can't be leveraged for Catalog Tasks.

 

Here is the link to the thread https://www.servicenow.com/community/now-platform-forum/how-does-generate-pdf-document-action-works-...

 

For generating the PDF you will have to rely on PDFGenerationAPI. the https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/sn_pdfgeneratorutils-namesp...

View solution in original post

Hey @Elena Spıru!

 

I believe I have!

 

You should be able to use the following script:

// Define variables
var recordSysId = [record_sysId],
    pdfTemplateSysId = [pdfTemplateSysId], //Found in the sn_doc_pdf_template table
    pdfName = [nameForPDF];
    tableName = [table_name_of_recordSysId]


// Setup field mapping
var fieldMap = {
    //This is where you map the field name from the PDF to the field name on the record
    "form1[0].page1[0].Part1[0].userName[0]": [record_field_name].getDisplayValue(),
    "form1[0].page1[0].typeReqDate[0]": [record_field_name].getDisplayValue(),
    "form1[0].page1[0].Part1[0].Organization[0]": [record_field_name].getDisplayValue()

};

// Execute API
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillDocumentFields(fieldMap, pdfTemplateSysId, tableName, recordSysId, pdfName);

 

Hopefully that helps!

 

View solution in original post

9 REPLIES 9

@Sandeep Rajput Here is the test I am running attachments. If you see anything wrong, please let me know.

@Austin_Brunet I did some search and found that the Generate PDF Document action only works with HR Templates. Unfortunately, this action can't be leveraged for Catalog Tasks.

 

Here is the link to the thread https://www.servicenow.com/community/now-platform-forum/how-does-generate-pdf-document-action-works-...

 

For generating the PDF you will have to rely on PDFGenerationAPI. the https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/sn_pdfgeneratorutils-namesp...

@Sandeep Rajput Thank you so much I really appreciate it!  

Hello! Did you manage to do this? I have a similar requirement. Thanks!

Hey @Elena Spıru!

 

I believe I have!

 

You should be able to use the following script:

// Define variables
var recordSysId = [record_sysId],
    pdfTemplateSysId = [pdfTemplateSysId], //Found in the sn_doc_pdf_template table
    pdfName = [nameForPDF];
    tableName = [table_name_of_recordSysId]


// Setup field mapping
var fieldMap = {
    //This is where you map the field name from the PDF to the field name on the record
    "form1[0].page1[0].Part1[0].userName[0]": [record_field_name].getDisplayValue(),
    "form1[0].page1[0].typeReqDate[0]": [record_field_name].getDisplayValue(),
    "form1[0].page1[0].Part1[0].Organization[0]": [record_field_name].getDisplayValue()

};

// Execute API
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillDocumentFields(fieldMap, pdfTemplateSysId, tableName, recordSysId, pdfName);

 

Hopefully that helps!