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.

Rushikesh5
Giga Guru

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

1 ACCEPTED SOLUTION

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

 

View solution in original post

11 REPLIES 11

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

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

 

Thank you buddy for your help.

It's working perfectly fine.

 

Thanks 

Please mark my answer as correct and close the thread. if it helped you

Saurav11
Kilo Patron
Kilo Patron

Hello,

Just create a new item menu with label Incident and type as scripted list in the SP header menu:-

find_real_file.png

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:-

find_real_file.png

 

Please mark answer correct/helpful based on Impact