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

Hi Brendan



I'm on Jakarta Patch 4 and it still seems to be working


Hi Brendan,



The   OOTB version of Jakarta "Header Menu" widget has been modified.


I cloned the widget and modified the code in the client controler to make it work. While cloning the widget   make sure you copy the templates from OOT to custom widget



$scope.$watch('data.menu.items', function() {


$scope.visibleItems = [];


if ($scope.data.menu.items) {


for (var i in $scope.data.menu.items) {


var item = $scope.data.menu.items[i];


//if (item.items || (item.scriptedItems && item.scriptedItems.count != 0))


if (item.items || (item.scriptedItems && item.scriptedItems.count >= 0)) // commented the above line and added this line to show "Requests" Tab on portal header


$scope.visibleItems.push(item);


}


}


}, true);



Thanks ,


Chandrashekar BN


Thanks, Chandra.   Altering the client script worked!


Hi Chandra,


long time no see buddy



I did this for a customer using Istanbul.


But now that they upgraded to Jakarta it stopped working, as you explained.



I tried your suggested solution already, though it didn't work for me..


Am I missing something?



// template:


<!-- "item.scriptedItems.showAlways" allows the menu item to show, set: "data.showAlways = true;" in the menu item's server script -->


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



// Request menu item:


var t = data;   // shortcut


t.items = [];


t.showAlways = true;



// Custom Header menu Client controller:


      //if (item.items || (item.scriptedItems && item.scriptedItems.count != 0))


      // commented the above line and added this line to show "Requests" Tab on portal header


      if (item.items || (item.scriptedItems && item.scriptedItems.count >= 0))


        $scope.visibleItems.push(item);


I got this request menu to always show, but problem is that even if its displayed, it seems like I'm unable to expand the drop down menu when clicking on it if the count is 0.


I need this because i want the first item in it (view all requests), to be accessible to view closed requests, even when there is no other currently active requests within the menu.