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

Nice. I think you can use ArrayUtil's diff method to simplify removing the public role.



//Script
action.setRedirectURL(current);
var arr = current.roles.toString().split(",");
var newroles = new ArrayUtil().diff(arr, ["public"]);
current.roles = newroles.toString();
current.update();


MB26
ServiceNow Employee
ServiceNow Employee

That's great thanks. I looked at that the script include for some sort of "remove" method, but didn't think about the diff capability. That can sure help in the future.