Add portal widget to Dashboard - ServiceNow Community
Gosia Urbanska
Giga Guru

 

 

 

Some time ago I was working on custom functionality for a dashboard. The way to go, was to use the AngularJS features. However, my standard UI Page setup for an angular didn't work here. Also, using ngCloak and angular.bootstrap didn't solve my issues.

 

My solution was:

1) create a standard portal widget with page (myWidget)-- add all my logic here

2) create a new UI Page (myUIpage) which I use as a container to display a portal page (myWidget)

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 <style>
        #preview{
            text-align: center;
        }
 </style>

     <div id="preview">     
       <iframe height="500" width="850" scrolling="no" src="/$sp?id=myWidget" />
    </div>
</j:jelly>

3) add my UI Page to a Dashboard widget 

function sections() {
    return {
		'SP Widget': {'name': 'myUIpage'}	
    };
}

function render() {
    var name = renderer.getPreferences().get("name");
    return renderer.getRenderedPage(name);
}

function getEditLink() {
    return "sys_ui_page.do?sysparm_query=name=" + renderer.getPreferences().get("name");
}

4) place a Dashboard widget on a Dashboard

 

and—voilà!— I got widget with nice AngularJS functionality  🙂

 

Comments
mat5
Giga Contributor

Does this still work?

I can display the portal page with this but I always get a 404 when trying to add "id=widget-cool-clock".

Varun16
Kilo Explorer

I can confirm it still works. I created an angular report in UI pages and i can display it on dashboard ( using system widget AND service portal widget) as described above. Big Thanks to the Auther @Gosia Urbanska .

Rick Forristall
Tera Guru

@mat5 did you ever figure this out?

 

When in the UI Page - you actually add the id to the portal page not the widget id - see code below. 

 

So the process is:
1. Create a portal widget that you want to appear on your dashboard

2. Create a portal page and include that widget

3. Create your UI page as below - linking to the id of the portal page - not widget

4. Create your UI widget (System UI > widgets)

5. Add the new System UI widget to your dashboard

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 <style>
        #preview{
            text-align: center;
        }
 </style>

     <div id="preview">     
       <iframe height="500" width="850" scrolling="no" src="/$sp?id=portalPageID" />
    </div>
</j:jelly>

 

SidharthJ
Tera Contributor

in the 3) step, somehow my renderer function is not working, can anyone plz tell me why?

Version history
Last update:
‎11-16-2018 03:22 PM
Updated by: