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,

 

we have one issue in portal request menu

Inactive RITMS are visible in sevice portal Request menu. I have opened one Request with 4 RITMs , closed 3 RITMS and one RITM is active , but RITM which is last RITM of the request (closed) is still visible in my request menu

Can any one please suggest how to fix this issue 

 

Regards

Anusha

larstange
Mega Sage

As I said you could introduce a new attribute in the item object and define this in the menu item script. Someting like (I haven't tested this)



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 way you can control it for individual menu options


Hi Lars,



Thanks again for your help so far, I really appreciate it.



I have tried what you have mentioned, however it hasn't seemed to work.   I know we are right there.



menuTemplate script:


<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 || item.showAlways" 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 || item.showAlways" items="item.scriptedItems.items" />



Server Script for the Menu Item


var t = data;   // shortcut


t.items = [];


t.count = 0;


t.showAlways = true;




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



Is the t.showAlways a variable that is already configured?   I am trying to work out how the menu script knows what t.showAlways means?



Cheers,


Brendan


Hi,


Can you please tell me as to how I can find this widget? Rather the exact name of this widget.


Which widget are you looking for, the menu item for my requests?


It is actually not a widget, its a menu item, which is why you're probably unable to locate it under the widget table.



There's more than just one way to locate this, one way is to just go to the menu table directly,


however, below ill explain the route I prefer, to ensure I access and edit the correct menu:



* type service portal in the navigator


* click on portals


* choose the default portal, marked with a green dot, most likely called sp


* form here access the current menu for this portal by clicking on the icon next to the header menu field on this portal form.


* from here you should be able to see all the related menu items for this menu form below under the menu items list.


* most likely you're looking for the one called "requests"