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.
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…
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…
A simple change to the URL (the addition of ‘nav_to.do?uri=’) adds navigation frames (and your instance logo) to the report.
By modifying the URL to include the navigation frames you can display your report like this…
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…
Name: Add Public Report Header
Global: True
Script:
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…
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;
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.
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!
You can. Just remove this section from the condition in the script…
is it possible to enter a coustomize text as a header by picking up any field values from the record
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.
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:
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 +''
});
}
}
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:
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 🙂
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
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.
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: ”});
}
}
has anyone got the report title to display on a published report in Calgary?