Service Portal 'Request' Menu Item - How to view closed tickets?

Brendan Hallida
Kilo Guru

Hi all,

Our Pilot users have discovered that when they do not have any active tickets, they cannot go in and see their inactive tickets

find_real_file.png

After all requests / incidents are closed, the menu item disappears.

find_real_file.png

Is there a way to make the menu item stay visible, even when there are no active tickets?

The code for the menu item (this is OOB)

var t = data;   // shortcut

t.items = [];

t.count = 0;

var u = gs.getUser().getID();

// 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});

var st = new GlideRecord('service_task');

if (st.isValid()) {

  st.addActiveQuery();

  st.addQuery('opened_by', gs.getUserID());

  st.orderByDesc('sys_updated_on');

  st.query();

  while (st.next()) {

      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);

      t.count++;

  }

}

var z = new GlideRecord('incident');

z.addActiveQuery();

z.addQuery('caller_id', gs.getUserID());

z.orderByDesc('sys_updated_on');

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.count++;

}

var z = new GlideRecord('sc_request');

z.addActiveQuery();

z.addQuery('requested_for', gs.getUserID());

z.orderByDesc('sys_updated_on');

z.query();

while (z.next()) {

  var ritm = new GlideRecord('sc_req_item');

  ritm.addQuery('request', z.getUniqueValue());

  ritm.query();

  if (!ritm.next())

      continue;

  var a = {};

  $sp.getRecordValues(a, z, 'sys_id,number,sys_updated_on');

  if (ritm.hasNext())

      a.short_description = ritm.getRowCount() + ' requested items';

  else

      a.short_description = ritm.cat_item.getDisplayValue() || ritm.getDisplayValue("short_description");

  a.__table = z.getTableName();

  a.type = 'request';

  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();

  t.items.push(a);

  t.count++;

}

t.items.sort(function(a, b) {

  return b.sortOrder - a.sortOrder;

});

var link = {};

link.title = gs.getMessage('View all requests');

link.type = 'link';

link.href = '?id=requests';

link.items = [];

t.items.unshift(link); // put this first

1 ACCEPTED SOLUTION

larstange
Mega Sage

item.showAlways should probably be item.scriptedItems.showAlways



When you declare property in a javascript object, it will be created. You don't have to worry about the property already existing.



If you want to be sure that the property actually exist you could do a console.log("MY DEBUG: " + item.scriptedItems.showAlways);


View solution in original post

37 REPLIES 37

Inactive_Us1474
Giga Guru

Try editing the below :


  1. t.record_watchers.push({'table':'sc_request','filter':'requested_for=' + u});   //13 Line
  2. //z.addActiveQuery();   55 Line

Thanks


Akhil


Hit Like/Helpful/Correct, if applicable.


Hi Akhil, thanks for responding.



I have changed those two lines, however the menu item is still not viewable when there are no active tickets.


Does anyone happen to have any more ideas?


Hi Brendan



I tried to do the same and its working fine - maybe you got a caching issue..



You might not want view all closed tickets as they will just pile up and become more and more.



I have configured mine to show active requests and requests created within the last 30 days.



t.record_watchers.push({'table':'sc_request','filter':'active=true^ORopened_atONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(0)^requested_for=' + u});


and



var z = new GlideRecord('sc_request');


//z.addActiveQuery();


//z.addQuery('requested_for', gs.getUserID());


z.addEncodedQuery('active=true^ORopened_atONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(0)^requested_for=' + u);


z.orderByDesc('sys_updated_on');


z.query();