Publish a UI page in a dashboard

Stewe Lundin
Mega Guru

Hi!

I'm trying to publish a UI Page as a Widget on a dashboard.

I'm getting;
Security constraints prevent access to requested page
Its a simple UI page writing out Hello World on the screen.
No JavaScript no nothing.
The code for the widget;

function sections() {

      return {

              'widget_name': { 'uiPageName' : 'hello_world'},

      };

}

function render() {

      var uiPageName = renderer.getPreferences().get("uiPageName");

      return renderer.getRenderedPage(uiPageName);

}

function getEditLink() {

      return "sys_ui_page.do?sysparm_query=name=" + renderer.getPreferences().get("uiPageName");

}

I have given the widget one of out public roles, and I'm running this with full admin.


What am I missing.  

10 REPLIES 10

Gowrisankar Sat
Tera Guru

The code that you are using works prior to fuji.



This code works with the scoped API and applies to custom and global applications on Fuji or later versions.



function sections() {


    return {


    'Widget': {


    'type': 'widgetname'


    }


    };


}



function render() {


    var scope = gs.getCurrentScopeName();


    scope = (scope == "rhino.global" ? "" : scope + "_");


    var page = renderer.getPreference('type');


    return renderer.getRenderedPage(scope + page);


}



function getEditLink() {


    var scope = gs.getCurrentScopeName();


    scope = (scope == "rhino.global" ? "" : scope + "_");


    var page = renderer.getPreference('type');


    return "sys_ui_page.do?sysparm_query=name=" + scope + page;


}



Check section 2 in the below page:


Using UI Pages as Gauges - ServiceNow Wiki


Thanks...
But there was more to this than just the code, apparently you can't use "_" [under score] in the UI Page name as well.


I realized that the code was a bit old pretty early.
But the underscore problem took me a while to figure out!


This was helpful, thank you. My UI Page is now showing as a widget correctly in my dashboard. I don't know why SNOW doesn't have this documented for how to use with a scoped application.  Maybe it is documented and I just cannot find it. The only SNOW documentation they have doesn't not mention scoped application at all. Also, the link you provided doesn't seem to have a section 2 nor solution for scoped application. 

Yash Agarwal
ServiceNow Employee
ServiceNow Employee

Hi @Stewe Lundin and @Todd O , can you please share the Code that you used to make it work. Its not working for me.

Thanks