Adding a Logo to Public Report Pages

///Adding a Logo to Public Report Pages

Adding a Logo to Public Report Pages

O

ne of the features of the Service-now reporting system is the ability to publish a report so that unauthenticated users can view certain reporting information about your environment. When a report is published, the system gives you a public URL that you can make available to your users. Users viewing a published report will see the report, but no additional information about your Service-now instance or company. In some cases, it may be desirable to add some identifying information to these published reports (like a company logo). In this article I’ll show you how that can be done.

Public Report-Logo

Here’s a screenshot showing the problem we’re trying to solve. We’ve got a nice published report that we would like to add a logo to…
Public Report

The first option is to make use of the built-in navigation frames in Service-now

When you publish a report, the system shows you a URL like this…

https://demo.service-now.com/sys_report_display.do?sysparm_report_id=a19bd425c611227b00232a5dc90c99a2

A simple change to the URL (the addition of ‘nav_to.do?uri=’) adds navigation frames (and your instance logo) to the report.

https://demo.service-now.com/nav_to.do?uri=sys_report_display.do?sysparm_report_id=a19bd425c611227b00232a5dc90c99a2

By modifying the URL to include the navigation frames you can display your report like this…
Public Report-Logo Navigation

The only problems with this method are that you can’t really control how that URL gets generated so you can’t always ensure that users will know about this trick, and the navigation frames won’t be included in the printable version so your logo will only be available when viewed in a browser.

The other option is a simple UI script to manipulate the report page itself

Usually when you’re dealing with non-standard forms in Service-now (like the report view page) the code can be found in a UI page or UI macro. In the case of the report pages however, the code is actually stored in back-end XML files. This makes it a bit harder to manipulate. I’ve written previously about a functionality I created to limit the reportable tables in Service-now. The technique I used to accomplish that modification is the same technique I’ll use here. It involves the creation of a global UI script that identifies when it is running on the report page and manipulates the page accordingly.

Here are the settings for the UI script you’ll need to create…

‘Add Public Report Header’ UI Script
Name: Add Public Report Header
Global: True
Script:

addLoadEvent(addPublicReportHeader);

function addPublicReportHeader(){
   if($('partialPage:theReport') && !$('reportform_control')){
      $('partialPage:theReport').insert({
         top: '<img src="http://www.sncguru.com/logo.png" class="chart"></img>'
      });
   }
}

The global UI script uses a couple of dom elements to identify whether or not it is running on the public report page. If it is, it simply adds the logo image. You can customize the ‘sncguru’ portion of the script to add the logo of your choosing. When you’re done, all of your public reports will display your logo at the top of the page like this…
Public Report-Logo

By | 2018-07-09T15:00:00-06:00 March 30th, 2011|Categories: UI scripts|Tags: , |12 Comments

About the Author:

12 Comments

  1. Daniel Styer March 30, 2011 at 7:59 am - Reply

    Sir:

    We have a requirement to add a classification to the top and bottom of the report. Can I replace the image with text from a field?

    top: incident.u_classification;

    bottom: incident.u_classification;

    • Mark Stanger March 30, 2011 at 8:24 am - Reply

      It’s probably possible, but it depends completely on what you can get to through the dom. It’s not as simple as querying or dot-walking to a field because you’re limited to client-side manipulation of the form. If you can pull that information from the form, then you can probably take it and display it where you want.

  2. Jason May 5, 2011 at 3:56 am - Reply

    Can this be done on internal reports as well? It’s not as necessary – I just think it looks cool. Thanks for the great tips and tricks. Keep them coming!

    • Mark Stanger May 5, 2011 at 4:06 am - Reply

      You can. Just remove this section from the condition in the script…

      && !$('reportform_control')
  3. mathew May 5, 2011 at 4:29 am - Reply

    is it possible to enter a coustomize text as a header by picking up any field values from the record

    • Mark Stanger May 5, 2011 at 4:32 am - Reply

      See my response to Daniel’s question above. It’s possible with some advanced scripting, but I don’t have anything pre-built to do this and it would depend on the setup of the report. You’re probably on your own if you decide to pursue it.

  4. Marc Guy June 1, 2011 at 12:32 am - Reply

    This may help in grabbing specific details from the actual report record itself, I recently was asked to add a footer to the bottom of the report, detailing the report title. I was able to grab the report title by grabbing the correct DOM element, script below:

    addLoadEvent(addPublicReportFooter);
     

     
    function addPublicReportFooter(){
     
    //Check to make sure we're on the public report page
     
    if($('partialPage:theReport')) //&& !$('reportform_control'))
     
    {
     

     
    var title = document.getElementById('sysparm_title').value;
     
    // alert(title);
     
    //Insert the footer
     
    $('partialPage:theReport').insert({
     
    bottom: '' + title +''
     
    });
     
    }
     
    }
  5. Marc Guy June 8, 2011 at 12:13 am - Reply

    My last update on this topic, I managed to put some more details on the report footer using a UI Script and a script include, this adds the user running the report and the date/time as well.

    If it actually printed when you use the print icon that would be even better but for some reason doesn’t 🙂

    A) Set up the script include mentioned in the wiki here: http://wiki.service-now.com/index.php?title=Set_C

    B) Create the ui script below:

    addLoadEvent(addPublicReportFooter);
     

     
    function addPublicReportFooter(){
     
    //Check to make sure we're on the public report page
     
    if($('partialPage:theReport')) //&& !$('reportform_control'))
     
    {
     

     
    var ajax = new GlideAjax('MyDateTimeAjax');
     
    ajax.addParam('sysparm_name','nowDateTime');
     
    ajax.getXMLWait();
     
    var rightnow = ajax.getAnswer();
     

     
    var title = document.getElementById('sysparm_title').value;
     
    //Insert the footer with report title - who ran report - and date-time run
     
    $('partialPage:theReport').insert({
     
    bottom: '' + title + ' - Run by ' + g_user.userName + ' at ' + rightnow + ''
     
    });
     
    }
     
    }

    If anyone can figure out how to get this on prints that would be very cool and useful to a lot of people in my opinion but I’m done 🙂

    • David Martin August 23, 2011 at 8:17 am - Reply

      Hi

      We have a header and footer, this works great in the application and when using the printer friendly version.

      Do you know if there is a way to add this functionality to a scheduled report? So when the report is sent via e-mail it includes the header and footer to the pdf file?

      Thanks

      • Mark Stanger August 23, 2011 at 8:26 am - Reply

        I’m not aware of a way to do that unfortunately. This technique works via client-side script so it is dependent on the report being viewed in the browser.

    • David November 14, 2014 at 8:48 am - Reply

      Would you happen to know how to add another button next to the “Export to PDF” button? I achieved to show a duplicated one but always shows at the very top of the form or the very bottom. Later on I would need to add the Excel export functionality. Thanks!

      Sample:

      addLoadEvent(addExportXLButton);

      function addExportXLButton(){
      if($(‘partialPage:theReport’) ){
      $(‘partialPage:theReport’).insert({top: ”});
      }
      }

  6. wes worek December 9, 2013 at 4:15 pm - Reply

    has anyone got the report title to display on a published report in Calgary?

Leave A Comment