Printer Friendly Version truncating fields

xiaix
Tera Guru

find_real_file.png

find_real_file.png

find_real_file.png

Why does this happen?

Better yet, where is the code behind (ui macro? ui script?) that is behind the "Print friendly version" function?  

9 REPLIES 9

xiaix
Tera Guru

Well, I found where the code is, but I don't think there's anything in there I can change to expand those fields to show all the data:




find_real_file.png



h t t p s://YOURINSTANCE.service-now.com/scripts/js_includes_navpage.jsx:



function printList(maxRows) {


      var mainWin = getMainWindow();


      if (mainWin && mainWin.CustomEvent.fire("print", maxRows) === false)


              return false;


      var veryLargeNumber = "999999999";


      var print = true;


      var features = "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=yes,location=no";


      var href = "";


      var frame = top.gsft_main;


      if (!frame)


              frame = top;


      if (frame.document.getElementById("printURL") != null) {


              href = frame.document.getElementById("printURL").value;


              href = printListURLDecode(href);


      }


      if (!href) {


              if (frame.document.getElementById("sysparm_total_rows") != null) {


                      var mRows = parseInt(maxRows);


                      if (mRows < 1)


                              mRows = 5000;


                      var totalrows = frame.document.getElementById("sysparm_total_rows").value;


                      if (parseInt(totalrows) > parseInt(mRows))


                              print = confirm(getMessage("Printing large lists may affect system performance. Continue?"));


              }


              var formTest;


              var f = 0;


              var form;


              while ((formTest = frame.document.forms[f++])) {


                      if (formTest.id == 'sys_personalize_ajax') {


                              form = formTest;


                              break;


                      }


              }


              if (!form)


                      form = frame.document.forms['sys_personalize'];


              if (form && form.sysparm_referring_url) {


                      href = form.sysparm_referring_url.value;


                      if (href.indexOf("?sys_id=-1") != -1 && !href.startsWith('sys_report_template')) {


                              alert(getMessage("Please save the current form before printing."));


                              return false;


                      }


                      if (isMSIE) {


                              var isFormPage = frame.document.getElementById("isFormPage");


                              if (isFormPage != null && isFormPage.value == "true")


                                      href = href.replace(/javascript%3A/gi, "_javascript_%3A");


                      }


                      href = printListURLDecode(href);


              } else


                      href = document.getElementById("gsft_main").contentWindow.location.href;


      }


      if( href.indexOf("?") <0 )


              href += "?";


      else


              href += "&";


      href = href.replace("partial_page=", "syshint_unimportant=");


      href = href.replace("sysparm_media=", "syshint_unimportant=");


      href += "sysparm_stack=no&sysparm_force_row_count=" + veryLargeNumber + "&sysparm_media=print";


      if (print) {


              if (href != null && href != "") {


                      win = window.open(href, "Printer_friendly_format", features);


                      win.focus();


              } else {


                      alert("Nothing to print");


              }


      }


}


function printListURLDecode(href) {


      href = href.replace(/@99@/g, "&");


      href = href.replace(/@88@/g, "@99@");


      href = href.replace(/@77@/g, "@88@");


      href = href.replace(/@66@/g, "@77@");


      return href;


}


Nia McCash
Mega Sage
Mega Sage

We ran into this problem with the short description field.  Filed a ticket with HI but were told: 

After carefully considering the severity and frequency of the issue, as well as the cost and risk of attempting a fix, a decision has been made not to address this issue in any current or future releases.

 

Thank you, niamccash, for posting your received HI response.  Such a shame to have pointed out an obvious flaw, it be in their control and abilities to fix, yet they're flat out going to ignore it.

I would expect that response from Micro$oft, not ServiceNow.

JP52
Mega Expert

Found myself in a similar problem. Here's what I came up with.

If you only need to modify one or two field(s) - Add a Field Style.

  1. Go to System UI -> Field Style and click new.
  2. Select your table and field and add a style:
    width:300px​;

 

If you want to apply style to all of the fields, the process get a bit more involved but is still rather simple.

The basic plan is to apply a style sheet to the "print view" by using a UI macro and Formatter. I've also added a UI Action on my form to open the print friendly view.

 

  1. Create a Style Sheet. go to Content Management -> Style Sheets and click New.
  2. Give it a name and make sure "Local Style Sheet" is selected.
  3. Add the Style you need and Save. For me, I added:
    .disabled {width:300px !important; }​
     (If you use the inspector tool in your browser, you can see the class of the field element is "disabled")
  4. Copy the sys_id of your new Style Sheet record.
  5. Next, we need a UI Macro to reference the Style Sheet. Go to System UI -> UI Macros and click New.
  6. Give it a name (like: print_view_style) and record the name you used, this will be required later. (If this is for a custom application, make sure your scope is set to the correct Application)
  7. Add the following inside the <j:jelly> tag and Save:
    <link href="<SYS_ID FOR YOUR STYLE SHEET>.cssdbx?" rel="stylesheet" type="text/css"/>​
  8.  (Optional) If you want to have any style modification (or other HTML added) only appear on the print view, you can add a conditional test (checking for &sysparm_media=print in the URL). Here is the complete result:
    <?xml version="1.0" encoding="utf-8" ?>
    <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    	<j2:if test="${sysparm_media=='print'}">
    		<link href="<SYS_ID OF YOUR STYLE SHEET>.cssdbx?" rel="stylesheet" type="text/css"/>
    	</j2:if>
    </j:jelly>​
  9. Now to pull it all together we need a UI Formatter to call the UI Macro. Go to System UI -> Formatters and click New.
  10. Give the Formatter a name that you will remember, this is what will appear in the Form Layout configuration.
  11. In the Formatter field, enter the name of your UI Macro suffixed with .xml. In this example it would be print_view_style.xml.
  12. Choose the appropriate table for the formatter to be used on and save. (Again, if this is for a custom application, be conscience of the scope you are in when you are creating all of these records)
  13. Finally, use the Form Layout configuration to add the new Formatter to the top of your Selected slushbucket.

 

Here is an example of the UI Action I use:

Client = Checked

Form button = Checked

Onclick = printView()

Script:

function printView() { 
	var sysparm_table = g_form.getTableName(); 
	var sysparm_sys_id = g_form.getUniqueValue().toString(); 
	var a='https://<YOUR INSTANCE>.service-now.com/';
	var view = 'Print_PO_View'; //Optional if you have a specific view you want
	g_navigation.openPopup(a + sysparm_table + '.do?sys_id=' + sysparm_sys_id + '&sysparm_record_rows=1&sysparm_view=' + view + '&sysparm_record_target=' + sysparm_table + '&sysparm_record_list=ORDERBYnumber&sysparm_record_row=1&sysparm_stack=no&sysparm_force_row_count=999999999&sysparm_media=print');
}

 

Hope that helps!