- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 04:59 PM
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.
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
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 02:13 PM
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.
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'
});
Johnny
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 07:11 PM
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2024 09:55 PM
Thanks for the reply, how do I fix the issue? the number is constantly shown over there
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2024 08:08 PM
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?
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 02:13 PM
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.
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'
});
Johnny
Please mark this response as correct or helpful if it assisted you with your question.