Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to add requested item group approvals to a pdf document

Community Alums
Not applicable

Hi, 

 

I have a requirement to create a pdf. The pdf need to contain variables from an RITM like name of user, serial number, model and date. they also want to add group approvals added to this. 

Using a BR to add the variables Is there any way to add the RITM group approvals ? Please help on this.

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

you can use OOB PDF Generation API, form the HTML string and convert it to pdf

check these links

Building a PDF report using PDFGenerationAPI 

Next-Gen PDF Generation – Part 1 

How to use ServiceNow PDF Generation API 

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

Community Alums
Not applicable

@Ankur Bawiskar 

any idea what the table name is for the RITM approvals groups and name to retrieve the approval info ? I tried with the variable ownership but no approvals information there

Community Alums
Not applicable

@Ankur Bawiskar 

 

Used the below code but the approvals don't populate In the pdf document. Please help 

 

(function executeRule(current, previous /*null when async*/ ) {

var instance = gs.getProperty('instance_name');
var wn = "<img src=\"https://" + instance + ".service-now.com/rps_logo_pdf.svg\" alt=\"RPSLogo\" width=\"150\" height=\"200\">" + "\n";

var vs = current.variables.equipment_details; //Change your variable set name here/////

var vsArr = JSON.parse(vs);
//current.stage.changesTo('Request Approved')

var pdfContent = '';
pdfContent += '<p style="color:blue;background-color: ">' + "Equipment Details for Requested Item :" + current.number + "</p>";


for (var k = 0; k < vsArr.length; k++) {
pdfContent = pdfContent + "<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\"><tbody><tr><td style=\"width: 50%;\"><b>&nbsp;" + vsArr[k].model_category_1 + ":" + "</b></td><td style=\"width: 50%;\">" + vsArr[k].serial_number_1 + "</td></tr></tbody></table>";
}

// pdfContent = pdfContent + '</table>';

var vardetstr = '';
var keys = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id);
set.load();

vardetstr += '<p style="color:blue;background-color: ">' + current.number + "\n Opened date :" + current.opened_at + "</p>";
vardetstr += '<p style="color:blue;background-color: ">' + " Opened date :" + current.opened_at + "</p>";

var vs1 = set.getFlatQuestions();
//gs.addInfoMessage('Test'+vs);
// for (var j = 0; j < vs1.size(); j++) {
// if (vs1.get(j).getLabel() != '') {

// vardetstr += "<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\"><tbody><tr><td style=\"width: 50%;\"><b>&nbsp;" + vs1.get(j).getLabel() + ":" + "</b></td><td style=\"width: 50%;\">" + vs1.get(j).getDisplayValue() + "</td></tr></tbody></table>";
// }
// }

for (i = 0; i < vs1.size(); i++) {
if (vs1.get(i).getLabel() != '' && JSUtil.notNil(vs1.get(i).getDisplayValue())) {
if ((vs1.get(i).getLabel() != 'Accept or Reject') && (vs1.get(i).getLabel() != 'Type of Relocation:') && (vs1.get(i).getLabel() != 'Is this Equipment Relocation in a Branch?') && (vs1.get(i).getLabel() != 'Is this request for you ?') && (vs1.get(i).getLabel() != 'Cost Centre Code') && (vs1.get(i).getLabel() != 'Corporate Grade') && (vs1.get(i).getLabel() != 'Mobile Number') && (vs1.get(i).getLabel() != 'Description:'))


var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('state', 'approved');
ritm.query();

while (ritm.next()) {
// Fetch approval records related to the RITM
var approvalGr = new GlideRecord('sysapproval_approver');
approvalGr.addQuery('document_id', ritm.sys_id);
approvalGr.query();

while (approvalGr.next()) {
var assignmentGroup = approvalGr.sysapproval.assignment_group.getDisplayValue();
var sysApproval = approvalGr.sysapproval.getDisplayValue();
var approver = approvalGr.approver.getDisplayValue();
var state = approvalGr.state;


}
}


{

vardetstr = vardetstr + "<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\"><tbody><tr><td style=\"width: 50%;\"><b>&nbsp;" + vs1.get(i).getLabel() + ":" + "</b></td><td style=\"width: 50%;\">" + vs1.get(i).getDisplayValue() + "</td></tr></tbody></table>";
}


}
}

var djj = wn + '\n\n\n' + vardetstr + '\n\n\n' + '\n\n\n' + pdfContent;
var p = new RPSPDF();
p.createPDF(prs, 'sc_req_item', current.getValue("sys_id"), current.number + '.pdf');
})(current, previous);