The CreatorCon Call for Content is officially open! Get started here.

generate a pdf of selected fields in a form using ui action

marrikruthi
Tera Contributor

 

var inc = current.number;
 
var pdfGenarator = new sn_pdfgeneratorutils.PDFGenerationAPI();
 
var pdfResult = pdfGenarator.convertToPDFWithHeaderFooter(inc, 'incident', current.sys_id, current.number + ' Number PDF');
 
if (pdfResult) {
    action.setRedirectURL('https://dev225695.service-now.com/sys_attachment.do?sys_id=' + pdfResult.attachment_id);
 
}

this script showing only field

Does anyone know how to modify the previous code to only include certain multiple fields?

Or alternatively how to create a pdf with only certain values.

7 REPLIES 7

Sid_Takali
Kilo Patron

Hi @marrikruthi Try this code

var inc = current.number;
var fieldsToInclude = ['short_description', 'description', 'priority']; 
var pdfGenerator = new sn_pdfgeneratorutils.PDFGenerationAPI();
var data = {};
fieldsToInclude.forEach(function(field) {
    data[field] = current[field];
});

var pdfResult = pdfGenerator.convertToPDFWithHeaderFooter(
    inc,
    'incident',
    current.sys_id,
    current.number + ' Number PDF',
    data // Pass the data object here
);

if (pdfResult) {
    action.setRedirectURL('https://dev225695.service-now.com/sys_attachment.do?sys_id=' + pdfResult.attachment_id);
}

@Sid_Takali
i have changed the above script with my requirements , but is not working can you please check the script that i have edited 

marrikruthi_0-1723107527468.png

 

 

ShubhamGarg
Kilo Sage

Hello @marrikruthi ,

 

Here are the links to some helpful resources -

Hope it helps.

 

Regards,

Shubham

marrikruthi
Tera Contributor

@Sid_Takali @ShubhamGarg 
Above information is not related to my requirement