Generate PDF file for catalog variables and attach it to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 11:14 PM
Hello There,
I need to create a PDF file with catalog variables and attach it to RITM as a PDF file. Has anyone attempted this before? or do you have any suggestions? Could you please paste the script below if you have done this?
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 07:09 AM
Working code:
(function executeRule(current, previous /*null when async*/ ) {
var v = new sn_pdfgeneratorutils.PDFGenerationAPI();
var tableName = current.getTableName();
var columLabels = ['number']; //As number field is derived from extended table
var grDict = new GlideRecord('sys_dictionary');
grDict.addEncodedQuery('name=' + tableName + '^internal_type!=collection^internal_typeISNOTEMPTY');
grDict.query();
while (grDict.next()) {
columLabels.push(grDict.element.getDisplayValue() + '');
}
var fields = '';
fields += "<table style='font-family: arial, sans-serif;border-collapse: collapse;width: 100%;'>";
for (f in columLabels) {
if (!columLabels[f].startsWith('sys_')) { //to avoid sys fields
if (fields.length > 0 && current[columLabels[f]].toString() != "") //if value exists in fields
fields += "<tr><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + current[columLabels[f]].getLabel() + "</th><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + current[columLabels[f]].getDisplayValue() + "</th></tr>";
}
}
var getVariable = new GlideRecord("sc_item_option_mtom");
getVariable.addEncodedQuery("request_item=" + current.sys_id);
getVariable.query();
while (getVariable.next()) {
fields += "<tr><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + getVariable.sc_item_option.item_option_new.getDisplayValue() + "</th><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + getVariable.sc_item_option.value.getDisplayValue() + "</th></tr>";
}
fields += "</table>";
var result = v.convertToPDF(fields, tableName, current.getUniqueValue(), current.number);
//action.setRedirect(current);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 01:22 AM - edited ‎02-10-2025 01:33 AM
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 01:25 AM
I replied to your question. This is an old thread and you might not get any response here
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 07:11 AM
(function executeRule(current, previous /*null when async*/ ) {
var v = new sn_pdfgeneratorutils.PDFGenerationAPI();
var tableName = current.getTableName();
var columLabels = ['number']; //As number field is derived from extended table
var grDict = new GlideRecord('sys_dictionary');
grDict.addEncodedQuery('name=' + tableName + '^internal_type!=collection^internal_typeISNOTEMPTY');
grDict.query();
while (grDict.next()) {
columLabels.push(grDict.element.getDisplayValue() + '');
}
var fields = '';
fields += "<table style='font-family: arial, sans-serif;border-collapse: collapse;width: 100%;'>";
for (f in columLabels) {
if (!columLabels[f].startsWith('sys_')) { //to avoid sys fields
if (fields.length > 0 && current[columLabels[f]].toString() != "") //if value exists in fields
fields += "<tr><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + current[columLabels[f]].getLabel() + "</th><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + current[columLabels[f]].getDisplayValue() + "</th></tr>";
}
}
var getVariable = new GlideRecord("sc_item_option_mtom");
getVariable.addEncodedQuery("request_item=" + current.sys_id);
getVariable.query();
while (getVariable.next()) {
fields += "<tr><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + getVariable.sc_item_option.item_option_new.getDisplayValue() + "</th><th style='border: 1px solid black;text-align: left;padding: 8px;'>" + getVariable.sc_item_option.value.getDisplayValue() + "</th></tr>";
}
fields += "</table>";
var result = v.convertToPDF(fields, tableName, current.getUniqueValue(), current.number);
//action.setRedirect(current);
})(current, previous);