How do i break page between two topics

pramn
Tera Guru

How do i break page between two topics 

pramn_0-1670430238835.png

Prier NCNTS Events  comes in different page 

12 REPLIES 12

@pramn This script include "GenerateAndAttachPDF" is not the OOTB script include. Seems like some plugin is installed to exporting the PDF. Please check the plugin details there might some configuration done for the table you are exporting data.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

var GenerateAndAttachPDF = Class.create();
GenerateAndAttachPDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/*
Description: Generate a PDF from HTML and attach to the record requested
Usage case: new GenerateAndAttachPDF('<p>Test&lt</p>', current.getTableName(), current.sys_id, 'export.pdf');
Returns: Attaches a pdf to the record table/sys_id provided. No return as such.
*/
createPDF : function(html, table, sys_id, filename) {
var pdfDoc = new GeneralPDF.Document(null, null, null, null, null, null);
this._document = new GeneralPDF(pdfDoc);
this._document.startHTMLParser();
this._document.addHTML(html);
this._document.stopHTMLParser();
this._saveAs(table, sys_id, filename);
},
/*
Description: Attaches generated PDF to the record inputted
Usage case: Private class, called only internally from this Script Include
Returns: Attaches a pdf to the record table/sys_id provided
*/
_saveAs : function (table, sys_id, filename){
var att = new GeneralPDF.Attachment();
att.setTableName(table);
att.setTableId(sys_id);
att.setName(filename);
att.setType('application/pdf');
att.setBody(this._document.get());
GeneralPDF.attach(att);
},
/*
Description: If this attachment has been attached to the same record before, delete it
Usage case: Call server side or it is also called by default from client callable function below
Returns: No return. Deletes records.
*/
removeDuplicateAttachments : function (sysid, filename) {
var alreadyAttach = new GlideRecord("sys_attachment");
alreadyAttach.addQuery("table_sys_id", sysid);
alreadyAttach.addQuery("file_name", filename);
alreadyAttach.query();
while (alreadyAttach.next()) {
alreadyAttach.deleteRecord();
}
},
/*
Description: Client Callable function to take advantage of the other functions above.
Returns: Attaches a pdf to the record table/sys_id provided
*/
attachFromClient : function(){
var html = this.getParameter('sysparm_html');
var table = this.getParameter('sysparm_table');
var sys_id = this.getParameter('sysparm_sysid');
var filename = this.getParameter('sysparm_filename');
//var filename = "export.pdf";
this.removeDuplicateAttachments(sys_id, filename);
this.createPDF(html, table, sys_id, filename);
},

type: 'GenerateAndAttachPDF'
});

@pramn Paste your html code here. Got the solution.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@pramn Got the HTML from other question. Please update the HTML as below that should solve your problem.

 

var ruleId = current.u_rule.split(","),
s;
var singleEmployees;
for (s = 0; s < ruleId.length; s++) {
if (gs.nil(singleEmployees)) {
singleEmployees = "u_ruleLIKE" + ruleId[s];
} else {
singleEmployees += "^ORu_ruleLIKE" + ruleId[s];
}
}



var ra2 = new GlideRecord('u_exception_request');
//ra2.addQuery('u_rule','IN', current.u_rule);
ra2.addEncodedQuery(singleEmployees);
ra2.addQuery('state', '!=', 7);
ra2.addQuery('state', '!=', 1);
ra2.addQuery('state', '!=', 8);
ra2.addQuery('number', '!=', current.number);
ra2.addQuery("u_submitted", "<=", current.u_submitted);
ra2.orderByDesc('u_submitted');
ra2.query();
// pramod
html += '<p style="page-break-before: always;"></p>';
html += '<table width="100%">';
html += '<tr><td><font size="2"><b>Prior NCNTS Events Associated with Rule(s)' + ' ' + ra2.getRowCount() +'</b></font></td></tr>';
html += '</table>';

 

html += '<table width="100%">';
// head 2
html += '<font size="1"><tr><td width="18%"><b>Exception Number</b></td><td><b>Exception Rule</b></td><td width="40%"><b>Short Description</b></td><td><b>Employee</b></td><td width="18%"><b>Submitted On</b></td><td width="18%"><b>Status</b></td></tr></font>';
// pramod end
if (!ra2.hasNext()) {
html += '<tr><td colspan="7"><font size="1">None</font></td></tr>';
} else {
var counts = 0;
while (ra2.next()) {
counts++;

 

html += '<tr>';
// html += '<td>' + ra.u_sequence_number + ' . ' + ra.u_remediation_action + ' - ' + ra.state.getDisplayValue() + ' - ' + ra.u_due_date + ' - ' + ra.assigned_to.getDisplayValue() + '</td>';
// html += '<td><font size="1">' + counts + '</font></td>';
html += '<td><font size="1">' + ra2.number + '</font></td>';
html += '<td><font size="1">' + ra2.u_rule.getDisplayValue() + '</font></td>';
html += '<td><font size="1">' + ra2.u_short_description + '</font></td>';
html += '<td><font size="1">' + ra2.u_employee_s.getDisplayValue() + '</font></td>';
// html += '<td><font size="1">' + ra2.u_submitted + '</font></td>';
html += '<td><font size="1">' + ra2.u_submitted.split(' ')[0] + '</font></td>'; //pramod
html += '<td><font size="1">' + ra2.state.getDisplayValue() + '</font></td>';
html += '</tr>';
}
}

 

html += '</table>';
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

pramn_0-1670479625547.png

still its mixing the page ...Remediation and NCNTS event coming in same page