The CreatorCon Call for Content is officially open! Get started here.

Published Report URL - where is it?

MB26
ServiceNow Employee
ServiceNow Employee

Recently I have been working with published reports. I have noticed and become frustrated with the fact that the published report URL only gets displayed immediately after you publish the report. Following that, good luck on finding it somewhere. You have to know the URL string and add a sys_id to the end of it. So here is a simple way of solving this.

I created a URL field on the sys_report table and created a client script to populate it, and display it if it is a published report. Here are the steps.

1. Create a new Field (of type URL)on the sys_report table. I called it "Published URL" (u_published_url).
2. Apply the following client script to the sys_report table.



function onLoad() {
var theroles = gel('sys_report.roles_nonedit');
checkroles = theroles.innerHTML;

if (checkroles.indexOf('public') >= 0) {
var reportid = g_form.getUniqueValue();
var reporturl = "sys_report_display.do?sysparm_report_id=" + reportid;
g_form.setValue('u_published_url',reporturl);
g_form.setDisplay('u_published_url', true);
}
else {
g_form.setDisplay('u_published_url', false);
}
}


Now you may ask, why a client script, and not a business rule?I could have created a business rule, but that would have to run on insert,update, or delete. Which is ok unless you already have a bunch of published reports. You would then have to run a background script to update all existing published reports. Although not that big a deal, I wanted the easiest drop in place method to accomplish this for anyone.

If you look at my screenshot, you will see that the URL is not your entire instance. If you hover over the URL, and refer to the status bar of your browser, you should see your entire instance URL. This is the nature of the URL field.

Good luck, let me know what you think.

11 REPLIES 11

CapaJC
ServiceNow Employee
ServiceNow Employee

This is awesome! And it addresses a limitation that shouldn't even be there.

I took your idea and played around a bit. I created a Business Rule on sys_report with a When value of "display" which is relatively new (wasn't in Fall 2010, but appeared in one of the subsequent Stable builds so will be in Winter 2011 in February). These run before display of a form and can thus add an InfoMessage to the top of the form. I used the following condition on the rule, which checks whether the public role is on the report using the ArrayUtil Script Include's "contains" convenience method:
new ArrayUtil().contains(current.roles.split(","), "public")

Then the following script (which makes use of the undocumented Report java class) gave me an InfoMessage at the top of the sys_report form with the published report's URL:
gs.addInfoMessage("This is a published report. URL: " + Packages.com.glide.report.Report(current.sys_id.toString()).publish());

So this won't yet work in the Fall 2010 release because the "display" value for the When field isn't available for business rules yet, but it would work going forward.


Any chance we could get this on both the back-end admin view and the front-end report view? Any time a report has been marked as public, you ought to be able to see that public URL.


Would also be nice to see an 'Un-publish' button in place of the 'Publish' button if a report is published. Currently the 'Publish' button just disappears and there's no way to Un-publish easily.


MB26
ServiceNow Employee
ServiceNow Employee

Very cool. And nice insight into the "Display" When value. Thanks.