- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 02:27 AM
Hi,
We are trying to export the RITM ticket details into PDF but the variables info is missing on PDF level.
we gone through the below community like, as per the suggestions we wrote script include, ui action and ui pages scripts.
https://community.servicenow.com/community?id=community_question&sys_id=bdd0b9e9db6c57487b337a9e0f961996
But after clicks on Print form we're getting blank image.
Can anyone help us, Many thanks for the support.
Note: we used same script which was available in the mentioned community link.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 05:19 AM
to show non empty variables add this
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.addEncodedQuery("sc_item_option.valueISNOTEMPTY");
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;
return desc;
},
type: 'fetchVariables1'
});
Please mark my response as correct and helpful to close the thread
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 02:34 AM
Hi,
any error in browser console or system logs?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 02:44 AM
Hi Ankur,
Many thanks for the reply..
Initially after clicking on Print form button we're getting like below
After clicks on print we're getting the above mentioned first image, no browser errors.
We're assuming that need to modify the script include, tried few possibilities but no luck,
Could you please check the bellow script include once:
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'
});
Many Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 04:09 AM
even same thing happening for me
I will have to explore and check and get back
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 04:10 AM
Sure.
Thanks for your time.