Service Portal Header badge count

JohnnySnow
Kilo Sage

Hi Team,

 

We have a header menu in our serviceportal which display all the tickets. I'm not sure why the count is showing up there, even though there is no updates to any of the tickets.

 

How can I modify the code so that it is displayed only when there is a genuine update. Also, even after  opening the My tickets link and going through the tickets, it still displays that number.

 

JohnnySnow_0-1725407692183.png

 

Below is code we have:

 

 
var max = 30;

var t = data;  
t.items = [];

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'incident','filter':'active=true^caller_id=' + u});
t.record_watchers.push({'table':'sc_req_item','filter':'active=true^request.requested_for=' + u});

var z = new GlideRecord('incident');
//z.addActiveQuery();
z.addQuery('caller_id', gs.getUserID());
z.addQuery('ORu_requestor', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
  var a = {};
  $sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on');
  if (z.short_description.nil())
    a.short_description = "(No description)";
  a.__table = z.getTableName();
  a.type = 'record';
  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a);  
}

var z = new GlideRecord('sc_req_item');
//z.addActiveQuery();
z.addQuery('request.requested_for', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
  var a = {};
  $sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on');
  if (z.short_description.nil())
    a.short_description = "(No description)";
  a.__table = z.getTableName();
  a.type = 'record';
  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a); 

 
}

t.items.sort(function(a, b) {
  return b.sortOrder - a.sortOrder;
});
t.items = t.items.slice(0, max); // only want first 30
t.count = t.items.length;
var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=requests', items: []};
t.items.unshift(link); // put 'View all requests' first
Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.
1 ACCEPTED SOLUTION

Hi Team,

 

We ended up creating a separate menu 'My Tickets' which would be displayed only when the user doesn't have any active tickets. This worked fine.

 

JohnnySnow_0-1727817090790.png

var portalQueryUtils = Class.create();
portalQueryUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



    getTicketCount: function() {

        var gaTickets = new GlideAggregate("task");
        gaTickets.addEncodedQuery(
            'sys_class_name=incident ^ ORsys_class_name=sc_req_item ^ ref_incident.caller_id=' + gs.getUserID() + '^ ORref_sc_request.requested_for=' + gs.getUserID() + '^ ORu_requestor=' + gs.getUserID() + ' ^active=true'
        );

        gaTickets.addAggregate('COUNT');
        gaTickets.query();

        if (gaTickets.next()) {
            var ticketCount = gaTickets.getAggregate('COUNT');
            return ticketCount;
        }
    },

    type: 'portalQueryUtils'
});
Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

AnirudhKumar
Mega Sage
Mega Sage

The number on the badge indicates the number of records that satisfy a condition... in this case, all the tickets (incident, RITM, etc.,) assigned to you. It does not reflect the records that have been updated...

Thanks for the reply, how do I fix the issue? the number is constantly shown over there

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

I tried to replicate the solution mentioned here https://www.servicenow.com/community/itsm-articles/display-service-portal-header-menu-items-with-zer... but even this doesnt seem to work, can some one please help me?

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

Hi Team,

 

We ended up creating a separate menu 'My Tickets' which would be displayed only when the user doesn't have any active tickets. This worked fine.

 

JohnnySnow_0-1727817090790.png

var portalQueryUtils = Class.create();
portalQueryUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



    getTicketCount: function() {

        var gaTickets = new GlideAggregate("task");
        gaTickets.addEncodedQuery(
            'sys_class_name=incident ^ ORsys_class_name=sc_req_item ^ ref_incident.caller_id=' + gs.getUserID() + '^ ORref_sc_request.requested_for=' + gs.getUserID() + '^ ORu_requestor=' + gs.getUserID() + ' ^active=true'
        );

        gaTickets.addAggregate('COUNT');
        gaTickets.query();

        if (gaTickets.next()) {
            var ticketCount = gaTickets.getAggregate('COUNT');
            return ticketCount;
        }
    },

    type: 'portalQueryUtils'
});
Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.