- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 02:20 AM
Hi All,
Can you please help me with this
Create one header menu named as "Incident" which will display the count of incidents assigned to the logged-in user.
In the header menu of the service portal, I wanted to show the number of incident counts.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 03:52 AM
data.items=[]; // Array to be displayed when clicked on menu
data.count=0; // Indicates number of records
var incGr = new GlideRecord('incident');
incGr.addQuery('caller_id',gs.getUserID())
incGr.query();
while(incGr.next()){
var obj={};
obj.title=incGr.getValue('number');
obj.type='link';
obj.href='/sp?id=ticket&table=incident&sys_id='+incGr.getUniqueValue();
data.items.push(obj);
data.count++;
}
use the above script in scripted list that will work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 03:13 AM
I tried this script mate, but for the incident, it's not working for me
Can u plz provide me with the correct script for the incident count
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 03:52 AM
data.items=[]; // Array to be displayed when clicked on menu
data.count=0; // Indicates number of records
var incGr = new GlideRecord('incident');
incGr.addQuery('caller_id',gs.getUserID())
incGr.query();
while(incGr.next()){
var obj={};
obj.title=incGr.getValue('number');
obj.type='link';
obj.href='/sp?id=ticket&table=incident&sys_id='+incGr.getUniqueValue();
data.items.push(obj);
data.count++;
}
use the above script in scripted list that will work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 04:09 AM
Thank you buddy for your help.
It's working perfectly fine.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 04:15 AM
Please mark my answer as correct and close the thread. if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2022 04:08 AM
Hello,
Just create a new item menu with label Incident and type as scripted list in the SP header menu:-
And paste the below script in Server script:-
// maximum number of entries in this Menu
var max = 30;
var t = data; // shortcut
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});
var st = new GlideRecord('service_task');
if (st.isValid()) {
t.record_watchers.push({'table':'service_task','filter':'active=true^opened_by=' + u});
st.addActiveQuery();
st.addQuery('opened_by', gs.getUserID());
st.orderByDesc('sys_updated_on');
st.setLimit(max);
st.query();
while (st.next()) {
if (!st.canRead())
continue;
var a = {};
$sp.getRecordValues(a, st, 'short_description,sys_id,number,sys_updated_on');
if (st.short_description.nil())
a.short_description = "(No description)";
a.__table = st.getTableName();
a.type = 'record';
a.sortOrder = st.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}
}
var z = new GlideRecord('incident');
z.addActiveQuery();
z.addQuery('caller_id', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
if (!z.canRead())
continue;
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
You will be able to see the Incident menu with count as below:-
Please mark answer correct/helpful based on Impact