How to rearrange items in the Service Portal Popular Items?

yltsai
Mega Guru

To all experts,

At this moment, many of you could be in K17. But when you get a breather, please help me with the following issue.

The client wants to rearrange the order in the Service Portal Popular Items.

I cloned the widget and modified the server code but it did not get the correct order. Please help and tell me what I missed.

Server Script:

data.sc_catalog = $sp.getValue('sc_catalog');

data.showPrices = $sp.showCatalogPrices();

var items = [];

var count = new GlideAggregate('sc_req_item');

//var count = new GlideRecord('sc_req_item');

//count.addAggregate('COUNT','cat_item');

count.groupBy('cat_item');

count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content');

count.addQuery('cat_item.sc_catalogs', data.sc_catalog);

//count.orderByAggregate('COUNT', 'cat_item');

count.orderBy('cat_item.order');

count.query();

while (count.next() && items.length < 9) {

  if (!$sp.canReadRecord("sc_cat_item", count.cat_item.sys_id.getDisplayValue()))

      continue; // user does not have permission to see this item

  var item = {};

  item.count = count.getAggregate('COUNT', 'cat_item');

  item.name = count.cat_item.name.getDisplayValue();

  item.short_description = count.cat_item.short_description.getDisplayValue();

  item.picture = count.cat_item.picture.getDisplayValue();

  item.price = count.cat_item.price.getDisplayValue();

  item.sys_id = count.cat_item.sys_id.getDisplayValue();

  items.push(item);

}

data.items = items;

1 ACCEPTED SOLUTION

yltsai
Mega Guru

The client did not want to show the Popular items, so the widget instance was removed. The client accepted the change.


View solution in original post

12 REPLIES 12

SusanWinKY
Kilo Sage

For what it's worth, we found that the Popular Widget (in Jakarta .0) was not sorting correctly.   It was sorting the count as a string instead of an integer.  



For example, we were seeing results come as:


1035


11789


1179


1200


12200


2300


255


27266


2727


etc.



To fix this, we changed this:



  item.count =   count.getAggregate('COUNT', 'cat_item');



to this:



  item.count =   parseInt(count.getAggregate('COUNT', 'cat_item'));



Has anyone else encountered this?



Susan Williams, Lexmark

Susan - yes! Just encountered this and your solution fixed it, thank you!

Have you upgraded since? Did you have to readjust that code in newer versions of ServiceNow?

Hi Steve,

We have upgraded from Jakarta to Kingston (patch 3) since I posted about this; however, we did not make any adjustments to this widget at that time.  Our customizations are working fine in our Kingston instance.

I haven't checked a personal developer instance of Kingston or London to see whether this has been fixed in the OOB widget.


Susan Williams, Lexmark