How do I print details from a RITM or SCTASK?

trishlipe
Giga Expert

We need a way to print the ticket Details to get sign off from end users.

When I export to a PDF document the details are not listed (See screenshot below). When I try to right click --> print, the format is not usable. How do I get this information to print on the PDF download?

find_real_file.png

1 ACCEPTED SOLUTION

Jag5
Tera Guru

Hi Trishlipe,

You can print the variables from RITM by creating a UI page, Script Include, and UI action.

Script Include: fetchVariables1, client callable = true

var fetchVariables1 = Class.create();

fetchVariables1.prototype = Object.extendsObject(AbstractAjaxProcessor, {
itemVariables: function() {
var itemID = this.getParameter('sysparm_item');
var displayValue = '';
var desc = '';
desc += '<table style="width:100%" cellpadding="0" border="1">';
desc += '<tr>';
desc += '</tr>';
var newLineHTML = '';
var variables ='variables.';
var grItem = new GlideRecord('sc_req_item');
grItem.get(itemID);
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item',itemID);
gr.orderBy('sc_item_option.order');
gr.query();
var i = 0;
while(gr.next()) {
variables ='variables.';
/* Put all variable values and labels from the variable pool into an array */
/* Only include non-empty variables, and exclude Label and Container variables */
//gr.sc_item_option.value.getDisplayValue() != '' gr.sc_item_option.value.getDisplayValue() != 'false'
if ( gr.sc_item_option.value.getDisplayValue() != 'false' && gr.sc_item_option.item_option_new.active == true && gr.sc_item_option.item_option_new.type != 11 && gr.sc_item_option.item_option_new.type != 19 && gr.sc_item_option.item_option_new.type != 20 && gr.sc_item_option.item_option_new.type != 14 ) {
//desc += j+") "+ v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue() + '<br>' ;
if(gr.sc_item_option.item_option_new.question_text == 'Current Annual Base' && i%2==1){
i++;
}
if(gr.sc_item_option.item_option_new.question_text == 'Current Supervisor' ){
//i++;
}
if(i%2==0) {
desc += '<tr>';
}
variables += gr.sc_item_option.item_option_new.name;
displayValue = grItem.getDisplayValue(variables);
if(displayValue==null || displayValue == undefined) {
displayValue = '';
}
if(gr.sc_item_option.item_option_new.question_text == 'Comments') {
newLineHTML += '<table style="width:100%" cellpadding="0" border="1">';
newLineHTML += '<tr><td style="text-align:left;padding:4px;width:20%;background: #80808040;"><span style="text-align:left;font-weight:900;padding:2px" >' + gr.sc_item_option.item_option_new.question_text + '</td><td style="width:80%;padding:4px;"></span><span style="text-align:left;white-space: pre-wrap;"> ' + gr.sc_item_option.value + ' </span></td></tr></table>';
}
else {
desc += '<td style="text-align:left;padding:4px;width:20%;background: #80808040;"><span style="text-align:left;font-weight:900;padding:2px" >' + gr.sc_item_option.item_option_new.question_text + '</td><td style="width:30%"></span><span style="text-align:left;white-space: pre-wrap;"> ' + displayValue + ' </span></td>';
}
if(i%2 == 1) {
desc += '</tr>';
}
i++;
}
}
desc += '</table>';
desc += newLineHTML;
},
type: 'fetchVariables1'
});

UI PAge: item_variables

HTML: 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<link href="kb_styles.cssx" type="text/css" rel="stylesheet" />
<div id ="html_content" style="display: none;">
$[sysparm_item]
</div>
<div id='printClass'>
<div id="commentsdiv" style="display: block;">
<h4 style="font-weight: bold;">Status Change Form for: $[sysparm_number]</h4>
<!--<table>
<span><label for="comments">$[sysparm_item]</label></span>
</table> -->


<div id="variable_data"></div>
</div>
</div>
<input type='button' id='btn' value='Print' onclick='printPage();'></input>
</j:jelly>

Client Script: 

var ga = new GlideAjax('fetchVariables1') ;
ga.addParam('sysparm_name','itemVariables');
ga.addParam('sysparm_item',document.getElementById('html_content').innerHTML);
ga.getXMLWait();
var val = ga.getAnswer();
//alert(val);
document.getElementById('variable_data').innerHTML = val;

function printPage()
{

var divToPrint=document.getElementById('printClass');

var newWin=window.open('','Print-Window');

newWin.document.open();

newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');

newWin.document.close();

setTimeout(function(){newWin.close();},10);

}

UI Action: Print Form, Table: Requested Item Onclick: printVariables()

function printVariables(){ //Client Side function

var sysid = g_form.getUniqueValue();

var gdw = new GlideModal('item_variables');
gdw.setTitle('Variables');
gdw.setWidth(1200);
gdw.setPreference('sysparm_number', g_form.getValue('number'));
gdw.setPreference('sysparm_item', g_form.getUniqueValue());
gdw.render();
}

 

Thanks,

Jag. 

 

Please mark CORRECT/HELPFUL as needed. 

 

 

 

View solution in original post

32 REPLIES 32

Hi Kavita,

 

You can add some code like below in the script include provided before "return desc" statement to get the multiline variables data.

var multiLineHTML = '';

var report = JSON.parse(grItem.variables.reassign_direct_reports); //name of the variable set
var lengthRep = report.length;

if(lengthRep > 0){

multiLineHTML = '<div>';
multiLineHTML +='<h4 style="font-weight: bold;">Multi Line Variables:</h4>';
multiLineHTML += '</div>';

multiLineHTML+= "<table id='dataTable1' style='table-layout: auto; background: transparent;border-collapse: collapse;' ><tbody><tr class='header' ><th style='border: 1px solid #dddddd; text-align: left;padding: 8px;'>Direct Report</th><th style='border: 1px solid #dddddd ; text-align: left;padding: 8px;'>Direct Report Manager</th>";

for (var j=0;j<lengthRep;j++){


var dr = report[j].direct_report; //variable name in variable set
var drm = report[j].direct_report_manager; //variable name in variable set

As the variables used here are reference to sys user table, we need to query the user table to get the name of the user. 


var drNew, drmNew;
var usrDR = new GlideRecord('sys_user');
usrDR.addQuery('sys_id', dr);
usrDR.query();
if(usrDR.next()){

drNew = usrDR.name;

}
var usrDRM = new GlideRecord('sys_user');
usrDRM.addQuery('sys_id', drm);
usrDRM.query();
if(usrDRM.next()){

drmNew = usrDRM.name;

}

multiLineHTML += '<tr>' + '<th style="border: 1px solid #dddddd; text-align: left;padding: 8px;">' + drNew+'</th>'+ '<th style="border: 1px solid #dddddd ; text-align: left;padding: 8px;">' +drmNew+'</th></tr>';

}
multiLineHTML += '</tbody></table>';
multiLineHTML += '</div>';
desc+= multiLineHTML;

}

desc += '</br>';

 

The output would be similar to below screenshot. 

find_real_file.png

 

 

 

Best,

Jag.

 

Please mark CORRECT/HELPFUL as needed. 

Kavitha Mulka
Tera Contributor

Hi Jag,

 

Thanks for Reply.

 

Actually I achieved Multi row variables with different codes. but same problem i observed from your screen shot that, Direct Report & Direct Report Manager is coming twice. Even for me also double labels coming. Am attaching screenshot. Please check. Any way to Hide those. And one more challenge is if we wrote any UI Policies or client script that are not working

Johaira Sarah F
Tera Contributor

.