Free Service Portal Widget: Related Lists

nathanfirth
Tera Guru

To help contribute back to the community, we're going to try to develop and give away one new widget per month.

For January we have developed the "Related List" widget, which allows you to display related lists on the form page in Service Portal.

Example below from a service catalog request:

Screen Shot 2017-01-12 at 10.20.55 AM.png

To download the widget, it's available on ServicePortal.io: Free Widget of the Month - ServicePortal.io - Service Portal, CMS, and Custom Apps

65 REPLIES 65

nthumma
Giga Guru

nathanfirth



for me, it's not showing count in the badge icon like you have in the original post, any thoughts?


Capture.JPG


The tabs are defined as below in the HTML. You'll see that the count is from "list.count", which in turn comes from "data.related_lists".


<ul class="nav nav-tabs" role="tablist">
      <li role="presentation" ng-class='{active:$first}' ng-repeat="list in data.related_lists">
              <a data-target="#{{list.table}}" aria-controls="{{list.table}}" role="tab" ng-class='{active:$first}' data-toggle="tab">
                      {{list.label}}
                      <span class="label label-as-badge label-primary" ng-if="list.count">{{list.count}}</span>
              </a>
      </li>
</ul>  
"data.related_lists" is populate through the server script in the snippet below. I'd suggest logging this variable out (in either server or client script - although client might be easier to debug) to see if the count is actually coming through. If it's there, it should be populated, and it's likely not showing just due to styling.
var f = $sp.getForm(data.table, data.sys_id, data.query);
data.f = f;
data.related_lists = f._related_lists;  

arthurcheung   data.f = f; was missing in my widget, I am not sure what else is missing. can you post the whole code for this widget?


EDIT: it's still not working though.



for (var i in data.related_lists) {


var list = data.related_lists[i];


gs.addInfoMessage('RL '+list.count);   // I am getting 0 here


var params = {


table: list.table,


filter: list.field+"="+data.sys_id,


view: 'sp',


title: list.label,


show_new: true


};



// object returning count as 0



  1. Object
    1. $$hashKey:"object:80"
    2. count:0
    3. field:"task"
    4. label:"CIs Affected"
    5. plural:"CIs Affected"
    6. table:"task_ci"
    7. type:"M2M"
    8. visible:true

Hi Nish,



We have customised the widget for specific use at a client, so I can't post the whole widget.



Also, my suggestion was to help you identify the problem, it wasn't actually the fix. So it only makes sense that it's still not working. You don't actually need data.f, we had added it there for our own purposes.



If you look closer, you'll see where data.related_lists is populated from. The fact that you are getting 0 in the count suggest that you should look at the call to:


$sp.getForm(data.table, data.sys_id, data.query);



Are you passing the right parameters in? If so, it could be a platform bug, in which case, what version of SNOW are you on? On glide-istanbul-09-23-2016__patch6-05-02-2017 this is returning as expected.



EDIT:


I've attached a widget I just created to make testing $sp.getForm easier. Just drop it onto a page and you can run it.


(function() {




data.f = {};


data.table = $sp.getParameter("t") || $sp.getParameter("table") || options.table;


data.sys_id = $sp.getParameter("sys_id") || options.sys_id;


data.query = $sp.getParameter("query");




if (!data.table || !data.sys_id)


return;


var f = $sp.getForm(data.table, data.sys_id, data.query);


data.related_lists = f._related_lists;


 




for (var i in data.related_lists) {


var list = data.related_lists[i];


var params = {


table: list.table,


filter: list.field+"="+data.sys_id,


view: 'sp',


title: list.label,


show_new: true


};




if (options.page) {


var page = new GlideRecord('sp_page');


if (page.get(options.page))


data.page = page.getDisplayValue('id');


}


if (!data.page) {


data.page = "form";


}




list.widget = $sp.getWidget('widget-data-table', params);


}




})();













can you see anything missing/wrong in above code. arthurcheung


I am on glide-jakarta-05-03-2017__patch0-05-18-2017.



screenshot-dev22202.service-now.com 2017-08-12 09-37-48.png