Export RITM ticket details into PDF

ar1
Kilo Sage

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.

find_real_file.png

 

Can anyone help us, Many thanks for the support. 

Note: we used same script which was available in the mentioned community link.

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

they forgot to return the desc in script include

Now it should work

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;
        return desc; // add this line
    },
    type: 'fetchVariables1'
});

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the support Anukr, 

Working like charm, But any idea how to show only user entered/selected variables, currently after clicks on print it's display all the variables including empty variables. Because on the RITM variable section the empty variable are not showing. 

 

Thanks

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Many many thanks for the Support Anukr.

Hi Ankur,

Checkbox variables are still showing even though it's not checked.?

Thanks.