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

yes in addition to Lars clear up cache using instance-name.com/cache.do


and also add one more thing to check if you are getting closed ones.


z.setLimit(10);



Thanks and Hope it helps.


Akhil


Hi Lars and Akhil.



Thanks for your input thus far



Ok so I think I am starting to get my head around the code for the menu items.   When I make the changes that you have suggested, it allows non active tickets to display in the actual menu and the count on the menu - this is actually not what I am after.   I like how it only shows the active tickets and counts.



Our issue is that when there are no active tickets - the whole menu item is removed.   We would like this menu item to still stay there if there are no active tickets, with just the link that says 'view all requests'.   This way they can go to the 'My Requests' Page and view their tickets.




Excuse my attempt at image manipulation and the 'My Open Items' name, it is still the same menu item.



Cheers,


Brendan


It looks like ServiceNow has done a good job making the menus dissapear if the record count is 0.



If you inspect the menu item, there is an if ensuring that it will only be displayed if there 1 or more items in the menu.



If you try and change the default count to one in the menu items script it will show up, but the count in the badge will be wrong


   



The if it self is defined in the Angular ng-Template "menuTemplate" which is related to the "Header Menu" widget. You might want to try and modify this and remove some of those ng-ifs.


Just remeber that it will affect all menu items.


Maybe you could introduce an extra attribute in the menu items data structure that could control the visibility when there items count is 0.



Cheers Lars,



We are on to something.



Below is the Angular ng-Template "menuTemplate" code.



<a ng-if="item.items.length == 0 && !item.scriptedItems" ng-href="{{item.href}}">{{ item.label }}</a>


<a ng-if="item.items.length > 0" href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ item.label }} <span class="caret"></span></a>


<ul ng-if="item.items.length > 0" class="dropdown-menu" role="menu">


      <li ng-repeat="item in item.items" ng-include="'menuTemplate'" />


</ul>


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


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


      <span ng-if="!item.scriptedItems.omitBadge" class="label label-as-badge label-primary sp-navbar-badge-count">{{item.scriptedItems.count}}</span>


</a>


<sp-dropdown-tree ng-if="item.scriptedItems.count >= 0" items="item.scriptedItems.items" />



I have edited rows 6 and 10 to include an "="


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



10. <sp-dropdown-tree ng-if="item.scriptedItems.count >= 0" items="item.scriptedItems.items" /> <!-- this allows the drop down to show




This brings the Request Menu up with 0 tickets and then I can click on the menu and then click on view all items



However - this brings another issue up - this also does the same for Approvals - which is something that I would like to keep the same as it was.   do you know how I could go about doing this?   they both seem affected by this code.





Cheers,


Brendan


I've followed this solution, and now see the Requests menu with the 0 badge, but when I click View all Requests, I'm not seeing anything, since there are no active requests.   How and where did you change the My Requests page to show all, or all from the past 30 days?