How to generate page number in the pdf through "Generate PDF" button on Impact analysis table(BCM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
1st you need to know which API that OOTB script include is using
did you check that?
generateDocument method within script include GenerateBiaPdfUtil?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar Below is the generateDocument method
generateDocument: function(biaName, docTemplateName) {
var templateId;
var docCategory;
var templateGr = this._getDocTemplate(
this.documentTemplateTable,
docTemplateName
);
if (templateGr && templateGr.isValid()) {
templateId = templateGr.getValue('sys_id');
docCategory = templateGr.getDisplayValue('category');
}
var docName = docCategory ? docCategory + '-' + biaName : biaName;
var docNameWithExt = docName + this.FILE_EXTENSION;
this.deleteExistingDocument(docNameWithExt);
var attachmentId = new sn_doc.GenerateDocumentAPI().generateDocumentForTask(
this.biaSysId,
templateId,
docName
);
var pdfDownloadLink = attachmentId ?
this._getPdfDownloadLink(attachmentId, biaName) :
null;
return {
attachmentId: attachmentId,
downloadLink: pdfDownloadLink ? pdfDownloadLink : biaName,
};
},And this method "generateDocumentForTask" is below
initiateDocumentTasks: function(taskGr, htmlBody, docTemplateId, generatedPdfName, documentId) {
var flowInputs = {};
flowInputs['task_record'] = taskGr;
flowInputs['template_id'] = docTemplateId;
flowInputs['generated_pdf_name'] = generatedPdfName;
flowInputs['document_id'] = documentId;
if (!gs.nil(htmlBody) && taskGr.document_template.sys_class_name.toString() == "sn_doc_html_template")
flowInputs['html_body'] = htmlBody;
var result = sn_fd.Subflow.startAsync('sn_doc.automatic_document_task_creation', flowInputs);
if (gs.nil(result) || gs.nil(result.contextId)) {
gs.error('Automatic Document Task Creation flow failed to start. Template ID: ' + docTemplateId +',Task ID: '+ taskGr.getValue('sys_id'));
return false;
}
var gr = new GlideRecord('sn_doc_task_execution');
gr.initialize();
gr.setValue('task',taskGr.sys_id);
gr.setValue('document_template',docTemplateId);
gr.setValue('flow_context',result.contextId);
gr.setValue('status','initiated');
gr.insert();
return true;
},
isDocumentTasksExecutionActive: function(taskGr, docTemplateId) {
var gr = new GlideRecord('sn_doc_task_execution');
gr.addQuery('task',taskGr.sys_id);
gr.addQuery('document_template',docTemplateId);
gr.addQuery('status','!=','closed');
gr.query();
return gr.hasNext();
},
generateDocumentForTask: function(recordId, documentTemplateId, pdfName) {
var isValid = this._validateUserAccess(documentTemplateId, recordId);
if (!isValid) {
gs.error("User do not access to the record");
return null;
}
var documentTemplateGr = this._getGlideRecord("sn_doc_template", documentTemplateId)();
var templateType = new DocumentTemplateUtils().getTemplateType(documentTemplateGr);
if (templateType == "sn_doc_pdf_template")
return new PdfTemplateUtils().generate(recordId, documentTemplateId, pdfName);
else if (templateType == "sn_doc_html_template")
return new HtmlTemplateUtils().generate(recordId, documentTemplateId, pdfName);
},
/**
* Description: Method to prefill pdf document with mapped values returns document as
* base64 content
* @param {SysId} recordId
* @param {SysId} documentTemplateId
* @return {{status: string, message: string, pdf_name:string, document_base64: string}}
*/
getPreFilledDocumentAsBase64: function(recordId, documentTemplateId) {
var response = {
"status": "error",
"message": "Error while generating pre-filled document"
};
var isValid = this._validateUserAccess(documentTemplateId, recordId);
if (!isValid) {
response.message = "Data is incorrect or User does not have access to the record";
return response;
}
try {
response = new PdfTemplateUtils().getPreFilledDocumentAsBase64(recordId, documentTemplateId);
}
catch(exception){
gs.error("Error generating the prefilled document as base64"+exception);
}
return response;
},
// Document template table should be same as recordTableName.
_validateUserAccess: function(documentTemplateId, recordId) {
if (gs.nil(documentTemplateId) || gs.nil(recordId))
return false;
var gRecord = new GlideRecord('sn_doc_template');
if (gRecord.get(documentTemplateId)) {
var tableName = gRecord.getValue('table');
if (gs.nil(tableName))
return false;
var record = new GlideRecord(tableName);
return record.get(recordId) && record.canRead();
}
return false;
},
_getGlideRecord: function(table, sysId) {
var gr = new GlideRecord(table);
return function(query) {
if (sysId)
gr.get(sysId);
else {
gr.addActiveQuery();
Object.keys(query).map(function(q) {
gr.addQuery(q, query[q]);
});
gr.query();
}
return gr;
};
},
type: 'GenerateDocumentAPISNC'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it looks like it's using OOTB GenerateDocumentAPI
see if that supports page number
if not then have your PDF Generation logic
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Read this Article for adding page number : Document Template: Dynamic Header and Footers
Also you can check :Generating Custom PDFs - using the new PDFGenerationAPI
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Tanushree Maiti The article you shared uses PDFGenerationAPI, while BCM code uses GenerateDocumentAPI. Those are different APIs.