Pin a catalog item to the list of popular items

Shannon Burns
Kilo Sage

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

1 ACCEPTED SOLUTION

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.


View solution in original post

14 REPLIES 14

Nate23
Mega Guru

Looks like you would have to edit the "SC Popular Items" widget.



The code just grabs the most used requested items. you would have to add a static value of your requested item to the "Items" array.



find_real_file.png


Yes, that's what I figured, but I'm just not great at coding, so wasn't sure how to do it.


First thing you need to do is determine how you will mark those "sticky" items that should always be included.   Will you add a boolean/checkbox to the Catalog Item (sc_cat_item table) to mark the ones that should be sticky?   Or, will you keep track of them using a custom System Property (sys_properties entry) which keeps track of the Sys IDs of the sticky items?



Then, perhaps the community can better help you with updating the widget code once we know more about how you plan on implementing the feature.


I figured I could just enter the sys_id.   Since it's just one or 2 items, it's not a big deal.