Service Portal Header Menu count

xiaix
Tera Guru

At the header of my Service Portal, I see:

find_real_file.png

I need this number to also count in records from a custom table.   Which widget script do I need to edit to add my custom table?

find_real_file.png

So the "Requests" count should not say 1, but 6

1 ACCEPTED SOLUTION

Erik Stolberg
Tera Guru

In the nav search, type sp_rectangle_menu_item.list, then search for Label = "Requests"



You'll see the commented text about record watchers. Add a new line with your table and filter to include in the count:


// use record watchers to tell header when to update dropdown counts


t.record_watchers = [];


t.record_watchers.push({'table':'service_task','filter':'active=true^opened_by=' + u});


t.record_watchers.push({'table':'incident','filter':'active=true^caller_id=' + u});


t.record_watchers.push({'table':'sc_request','filter':'active=true^requested_for=' + u});


View solution in original post

9 REPLIES 9

Hi Erik,

I have similar requirement for ESC (Employee Center portal) like My Requests on header its not showing Count could you help on this case?

find_real_file.png

sethhumphrey
Mega Guru

The click path to get to this file would be:

Service Portal > Menus > Title = "SP Header Menu" > Requests

 

I added watchers for Changes and Calls:

t.record_watchers.push({'table':'change_request','filter':'active=true^opened_by=' + u});
t.record_watchers.push({'table':'new_call','filter':'caller.sys_id=' + u});

var cr = new GlideRecord('change_request');
cr.addActiveQuery();
cr.addQuery('opened_by', gs.getUserID());
cr.orderByDesc('sys_updated_on');
cr.setLimit(max);
cr.query();
while (cr.next()) {
  var a = {};
  $sp.getRecordValues(a, cr, 'short_description,sys_id,number,sys_updated_on');
  if (cr.short_description.nil())
    a.short_description = cr.getDisplayValue("short_description")
  a.__table = cr.getTableName();
  a.type = 'record';
  a.sortOrder = cr.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a);
}

var call = new GlideRecord('new_call');
call.addActiveQuery();
call.addQuery('caller.sys_id', gs.getUser().getID());
call.orderByDesc('sys_updated_on');
call.setLimit(5);
call.query();
while (call.next()) {
  var a = {};
  $sp.getRecordValues(a, call, 'short_description,sys_id,number,sys_updated_on');
  if (call.short_description.nil())
    a.short_description = "(No description)";
  a.__table = call.getTableName();
  a.type = 'record';
  a.sortOrder = call.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a);
}

 

Hi, I have a Custom table (u_sample) which is similar to incident and it doesn't extent task table. Users submit records to this table using the portal.  I am not able to see these records in "My request " tab in Service portal header, I only see Requests and Incidents.

find_real_file.png

I added the code as mentioned in the thread, still no luck. Can someone please help me with this. 

Code that I modified: 

// 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_request','filter':'active=true^requested_for=' + u});
t.record_watchers.push({'table':'u_sample','filter':'u_user=' + u});


var call = new GlideRecord('u_sample');
call.addActiveQuery();
call.addQuery('u_user', gs.getUserID());
//call.addQuery('u_user.sys_id', gs.getUser().getID()
call.orderByDesc('sys_updated_on');
call.setLimit(max);
call.query();
while (call.next()) {
if (!call.canRead())
continue;
var a = {};
$sp.getRecordValues(a, call, 'sys_id,u_number,sys_updated_on');
if (call.short_description.nil())
a.short_description = "(No description)";
a.__table = call.getTableName();
a.type = 'record';
a.sortOrder = call.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);

 

 

Maybe you just didn't paste it, but there should be a closing curly brace to wrap up that while statement at the bottom:

// 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_request','filter':'active=true^requested_for=' + u});
t.record_watchers.push({'table':'u_sample','filter':'u_user=' + u});

var sample = new GlideRecord('u_sample');
sample.addActiveQuery();
sample.addQuery('u_user', gs.getUserID());
sample.orderByDesc('sys_updated_on');
sample.setLimit(max);
sample.query();

// use this to debug what is coming out
console.dir(sample);

while (sample.next()) {
 if (!sample.canRead())
  continue;
 var a = {};
 $sp.getRecordValues(a, sample, 'sys_id,u_number,sys_updated_on');
 if (sample.short_description.nil())
  a.short_description = "(No description)";
 a.__table = sample.getTableName();
 a.type = 'record';
 a.sortOrder = sample.sys_updated_on.getGlideObject().getNumericValue();
 t.items.push(a);
}

Also add some console dumps so you can debug.  I added one above.

The above code is just to get those to show up in your nav menu.  If you want them to show up in the widgets from your screenshot, you'll need to update those separately.