- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 09:37 AM
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;
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 12:14 PM
The client did not want to show the Popular items, so the widget instance was removed. The client accepted the change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 10:07 AM
Hello,
In your array of items[ ]; you could display them in however order you want by using a specific number like so.
items[3];
items[4];
items[1];
items[0];
items[6];
etc..
Printing in a standard for loop will display in whatever order the server chooses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 10:27 AM
Patrick,
Did you suggest to hard-coded assign the items array?
Would it be better to write a code as count.orderBy('cat_item.order');
By the way, I modified the OOB code and the items was defined as a list.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 10:48 AM
I agree that it would be better to use orderBy. Can you change the order at all? Have you tried something like gr.orderByDesc('sys_created_on');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 11:07 AM
It was in my script to use orderBy but it does not work. Therefore, I have to ask for help from all Service Portal experts.
Regards,