The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Service Portal Favorites Widget Help

Chaz
Giga Guru

Hello Community,

I'm working on a Favorites Widget for the Service Portal. I'm using the widget coding shared by mhedtke24 in post:

https://community.servicenow.com/community?id=community_article&sys_id=f8e3562fdb21e300107d5583ca96196f

 

I've modified the scripts to allow our users to Favorite Knowledge Articles & Service Catalog Items. The only issue is I want to have an icon differentiating whether the favorited item is an article or a catalog item. I'm trying to create a condition by indexing the URL of the bookmark but I think I've got the code in the wrong location as it's showing all items with the same icon rather than the correct icon the item should be associated with.

Example

find_real_file.png

HTML

<div>

  <div class="panel-heading" >
    <label class="panel-title">
      <i class="fa fa-star m-r-sm"></i>
      ${My Favorites}
    </label>
  </div>


  <div class="list-group" >
    <div ng-if="c.data.fav.hasAny == false" class="list-group-item">
      ${ You do not have any favorites }
    </div>
    <div class="list-group-item" ng-repeat="item in c.data.fav" >
      <i class="icon-catalog" ng-if="item.showTicket"></i>
      <i class="icon-article-document" ng-if="item.showKnowledge"></i>
      <a ng-href="{{::item.url}}" uib-tooltip="Go to favorite">{{item.short_description}}</a>
      <i class="fa fa-trash-o fav-icon" ng-click="c.removeFav(item.sys_id)" uib-tooltip="Remove from favorites" tooltip-placement="right" tooltip-append-to-body="true"></i>
    </div>
  </div>

</div>

 

Client Script

function($scope,spUtil,$window) {

	var c = this;
	
	if (c.data.fav.length > 0) {
		c.data.fav.hasAny = true;
	}
	else {
		c.data.fav.hasAny = false;
	}

	c.removeFav = function(value) {
		c.data.remove = value;
		c.server.update()         
		spUtil.update($scope);
	}
}

 

Server Script

(function() {

	var t = data;
	var z = new GlideRecord('sys_ui_bookmark');
	z.addQuery('user', gs.getUserID());
	z.addQuery('url', 'STARTSWITH', '/kb');
	z.orderByDesc('sys_created_on');
	z.query();
	t.rowCount = z.getRowCount();
	t.fav = [];

	while (z.next()) {
		var a = {};
		a.short_description = z.getValue('title');
		a.sys_id = z.getValue('sys_id');
		a.url = z.getValue('url');
		
		if(a.url.indexOf("sc_cat_item")){
			a.showTicket = true;
			a.showKnowledge = false;
		}
		else if(a.url.indexOf("kb_knowledge")){
			a.showKnowledge = true;
			a.showTicket = false;
		}
		else{
			a.showTicket = false;
			a.showKnowledge = false;
		}
		t.fav.push(a);
	}

	// Delete favorite
	if (input && input.remove) {
		var bmGR = new GlideRecord('sys_ui_bookmark');
		bmGR.addQuery('user', gs.getUserID());
		bmGR.addQuery('sys_id', input.remove);
		bmGR.query();
		if (bmGR.next()) {
			bmGR.deleteRecord();
		}
	}
})();

 

 

1 ACCEPTED SOLUTION

Thank you for this information.

This made a bell ring for me and I was able to utilize the "window_name" field to show the icon specific to the favorites.

View solution in original post

2 REPLIES 2

sachin_namjoshi
Kilo Patron
Kilo Patron

I had blog for bookmark widget.

You can reuse same code since favorites are also maintained in bookmark table.

 

https://community.servicenow.com/community?id=community_blog&sys_id=5d6f964bdbd4d3445322f4621f961917

 

Regards,

Sachin

Thank you for this information.

This made a bell ring for me and I was able to utilize the "window_name" field to show the icon specific to the favorites.