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

yltsai
Mega Guru

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


What did you end up replacing it with yltsai?


Since the client did not want to display the Popular items, we removed the widget instance. It left a big blank space on the page with a simple Catalog item list on the left.



Thank you,


Interesting, thanks!


Sona1
Kilo Contributor

Hello,



I have similar problem like i want to arrange the catalog items in   Popular Items Widget according to their access.


That means i want to display the most recently accessed cat item first and then 2nd most recently accessed and so on.


Can anyone help?