Need to generate PDF with all the fields when end user submit a catalog

AkashL722774083
Tera Contributor

When an end user submits a catalog through the portal, the system should automatically generates a PDF document containing all the submitted information.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@AkashL722774083 

you can use PDF Generation API

check this link which has script from Piyush

Generate PDF file for catalog variables and attach it to RITM 

you can check the PDF Generation API for this

Generating Custom PDFs - using the new PDFGenerationAPI

another method

Generate PDF and attach to the record

When catalog item is submitted, attach variables to RITM as a PDF 

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

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

View solution in original post

@AkashL722774083 

Hope you are doing good.

Did my reply answer your question?

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

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

View solution in original post

9 REPLIES 9

Thanks for the help

Thanks for helping

@AkashL722774083 

Hope you are doing good.

Did my reply answer your question?

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

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

Bhimashankar H
Mega Sage

Hi @AkashL722774083 ,

 

I hope you saw my reply. 


If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. It will help future readers as well having similar kind of questions and close the thread.

Thanks,
Bhimashankar H

Rafael Batistot
Kilo Patron

Hi @AkashL722774083 

 


This code might help you 

 

(function() {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item', '<catalog_id>'); // Replace with your Catalog Item sys_id
gr.query();
while (gr.next()) {
createPDF(gr); // pass each RITM
}

function createPDF(ritmGr) {
var html = "<h2>Catalog Request Details</h2>";
html += "<p><b>Requested For:</b> " + ritmGr.request.requested_for.getDisplayValue() + "</p>";
html += "<p><b>Catalog Item:</b> " + ritmGr.cat_item.getDisplayValue() + "</p>";
html += "<hr/>";

// Collect Variables
var catGr = new GlideRecord('sc_item_option_mtom');
catGr.addQuery('request_item', ritmGr.sys_id);
catGr.query();
while (catGr.next()) {
var optionGr = new GlideRecord('sc_item_option');
if (optionGr.get(catGr.sc_item_option.toString())) {
var label = optionGr.item_option_new.getDisplayValue(); // variable label
var value = optionGr.value; // submitted value
html += "<p><b>" + label + ":</b> " + value + "</p>";
}
}

// Generate PDF and attach to RITM
var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();
var attachmentId = pdfAPI.convertToPDFWithAttachmentName(
html,
ritmGr,
"Catalog_Request_" + ritmGr.number + ".pdf"
);

gs.info("PDF generated and attached: " + attachmentId);
}
})();

 

The PDF will be save in the RITM generate