
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 06:11 AM
Does anyone know an easy way to always include a particular item as one of the popular items in the service portal widget?
My boss wants a particular thing to show up there (regardless of how many times it was actually requested).
Thanks,
Shannon
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 07:52 AM
Not ideal/best practice - you'll undoubtedly want to change this as some point and having to re-code the widget isn't an ideal way of updating this. Personally and without knowing further details about your use case or environment, I'd lean towards a System Property.
But here's some quick, untested code that you can try in the Server Script of your widget to get a particular catalog item included. Add to about line 5 of the OOB server script just after var items = [];
var sticky = new GlideAggregate('sc_cat_item');
sticky.addQuery('sys_id','[INSERT SYS ID HERE]');
sticky.query();
while (sticky.next()) {
if (!$sp.canReadRecord("sc_cat_item", sticky.sys_id))
continue; // user does not have permission to see this item
var item = {};
item.name = sticky.name.getDisplayValue();
item.short_description = sticky.short_description.getDisplayValue();
item.picture = sticky.picture.getDisplayValue();
item.price = sticky.price.getDisplayValue();
item.sys_id = sticky.sys_id.getDisplayValue();
items.push(item)
}
EDIT: jacob.benker had a good presentation on Data Driven Development (including how to leverage System Properties for use cases like these) in Creator Con breakout session (CCB4208) at Knowledge17 just last week.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 07:52 AM
Not ideal/best practice - you'll undoubtedly want to change this as some point and having to re-code the widget isn't an ideal way of updating this. Personally and without knowing further details about your use case or environment, I'd lean towards a System Property.
But here's some quick, untested code that you can try in the Server Script of your widget to get a particular catalog item included. Add to about line 5 of the OOB server script just after var items = [];
var sticky = new GlideAggregate('sc_cat_item');
sticky.addQuery('sys_id','[INSERT SYS ID HERE]');
sticky.query();
while (sticky.next()) {
if (!$sp.canReadRecord("sc_cat_item", sticky.sys_id))
continue; // user does not have permission to see this item
var item = {};
item.name = sticky.name.getDisplayValue();
item.short_description = sticky.short_description.getDisplayValue();
item.picture = sticky.picture.getDisplayValue();
item.price = sticky.price.getDisplayValue();
item.sys_id = sticky.sys_id.getDisplayValue();
items.push(item)
}
EDIT: jacob.benker had a good presentation on Data Driven Development (including how to leverage System Properties for use cases like these) in Creator Con breakout session (CCB4208) at Knowledge17 just last week.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 11:14 AM
With one little change (sc_cat_item in line 1 instead of sc_req_item), it worked perfect!
Thanks! I do hate hardcoding things. I am under a bit of a time constraint. But I will put it on my list to go back and try to make it more data driven. Thanks for the heads up about that session!
Shannon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 11:17 AM
Whoops... Thanks for catching that. Fixed the original script above in case others stumble upon this thread and copy and paste.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 01:36 PM
Thanks for the mention!! I'm glad you enjoyed the session!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 05:46 AM
Hi!
I've found this code really helpful and used it to pin a catalog item to the Popular Items list - fab!
Only problem is, when you then click the pinned item from the Popular Items list, it doesn't take you to the form, it takes you back to the Homepage?!? Any ideas?
Any help greatly appreciated!
Thanks