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

var t = data;   // shortcut


t.items = [];


t.count = 0;


t.showAlways = true;



Then in the template add this attribute to the if



6. <a ng-if="item.scriptedItems.count > 0 || item.scriptedItems.showAlways" href="javascript:void(0)" data-toggle="dropdown" title="{{item.hint}}"> <!-- this allows the menu item to show



This should be the correct answer, not the one stated.


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


Cheers Lars, that did the trick.



I really appreciate your help today, and I am starting to get a hang of this javascript stuff.



Thanks again, and if you are ever in Sydney give me a shout - ill buy you a beer!



Cheers,


Brendan


Hi All,



I tried with the mentioned steps but it is not working.



Below is the code




Menu Item



// maximum number of entries in this Menu


var max = 30;



var t = data;   // shortcut


t.items = [];


t.showAlways=true;




menuTemplate



<a ng-if="item.scriptedItems.count > 0 || item.scriptedItems.showAlways" href="javascript:void(0)" data-toggle="dropdown" title="{{item.hint}}">


      <span ng-bind-html="item.label"></span>




Thanks,


Chandrashekar BN


Hey Chandra,



What version are you on?   after updating to Jakarta Patch 4, this has stopped working and now I am back to the drawing board.



Cheers,


Brendan