show incident count on header menu in service portal?

priyanka58
Tera Contributor

Create one header menu named as"Incident" which will display the count of incidents assigned to the logged in user.

I need to do this using scripting.

1 ACCEPTED SOLUTION

Hello Priyanka,

Did it work?

View solution in original post

10 REPLIES 10

VigneshMC
Mega Sage

Below link should be helpful

https://community.servicenow.com/community?id=community_question&sys_id=7033c7e1dbd8dbc01dcaf3231f9619db

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

Hello,

This incident menu item is not showing in the header menu so please could you tell me how to do that.

Please show me your configuration screenshot