Blog

Closed Tickets Menu Item

How to add a closed tickets menu item to your service portal

Menu Item

  1. Go to Left Navigation Bar > Service Portal > Menus

  2. Click the one with SP Header Menu as the title

  3. New Menu Item: Closed Tickets

    Label: Closed Tickets
    Parent Menu: SP Header Menu
    Type: Scripted List
    Condition: gs.isLoggedIn()
    Server Script:
    // maximum number of entries in this Menu
    var max = 30;
    
    var t = data;  // shortcut
    t.items = [];
    
    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=false^opened_by=' + u});
    t.record_watchers.push({'table':'incident','filter':'active=false^caller_id=' + u});
    t.record_watchers.push({'table':'sc_request','filter':'active=false^requested_for=' + u});
    
    var st = new GlideRecord('service_task');
    if (st.isValid()) {
      st.addQuery('active','false');
      st.addQuery('opened_by', gs.getUserID());
      st.orderByDesc('sys_updated_on');
      st.setLimit(max);
      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);
      }
    }
    
    var z = new GlideRecord('incident');
    z.addQuery('active','false');
    z.addQuery('caller_id', gs.getUserID());
    z.orderByDesc('sys_updated_on');
    z.setLimit(max);
    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);
    }
    
    var z = new GlideRecord('sc_request');
    z.addQuery('active','false');
    z.addQuery('requested_for', gs.getUserID());
    z.orderByDesc('sys_updated_on');
    z.setLimit(max);
    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.items.sort(function(a, b) {
      return b.sortOrder - a.sortOrder;
    });
    t.items = t.items.slice(0, max); // only want first 30
    t.count = t.items.length;
    
    var link = {title: gs.getMessage('View all closed tickets'), type: 'link', href: '?id=closedrequests', items: []};
    t.items.unshift(link); // put 'View all requests' first

Add Closed Tickets Page

Top Container

  1. Go to Left Navigation Bar > Service Portal > Menus

  2. Click New

  3. Title: Closed Tickets, ID: closedrequests

  4. Right-Click and Save

  5. Open in Designer

  6. Add a 9|3 block

  7. Add the breadcrumbs widget to the 9 block

  8. Add the Typeahead search to 3 block

  9. For the top container, set the Parent container to “breadcrumbs-container”

  10. Click “Move to header”

  11. Click Save

Bottom Container

  1. Add another container

  2. Add a 12 block

  3. Add Simple List

Title: My Closed Incidents
Table: Incident
Filter: caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^active=false^EQ
Display field: short description
Secondary fields: number, updated
Link to this page: ticket

4. Clone the "My Requests" Widget

Title: My Closed Requests
ID: my_closed_requests
Change line 5 of the server script
	gr.addQuery('active','false');
Click save

5. Add My Closed Requests Widget to the form.

6. Add a Service Tasks Simple list too (if you use that feature)