Service Portal - Scripted Lists

SusanWinKY
Kilo Sage

Hi all,

We created a Request History scripted list so it displays many types of tasks:  incidents, change requests, catalog items (RITMs), and others.

We set this up so the RITMs were included with these queries.

For the badge watcher:

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'sc_req_item','filter':'requested_for=' + u + '^ORopened_by=' + u}); 

To get the list of RITMs (the menu displays the top 10 of all tasks by last modified date):

var z = new GlideRecord('sc_req_item');
z.addEncodedQuery('requested_for=' + gs.getUserID() + "^ORopened_by=" + gs.getUserID());
z.orderByDesc('sys_updated_on');
z.query();
totalItemsCount = totalItemsCount + z.getRowCount();
z.setLimit(max);
z.query();
while(z.next()){
  var a = {};
  $sp.getRecordValues(a, z, 'sys_id,number,sys_updated_on');
  a.short_description = z.cat_item.getDisplayValue();
  a.__table = z.getTableName();
  a.type = 'record';
  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a);
}

And to create the URL that opens when the user clicks "View all requests":

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe";
var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=list&table=task&view=portal&filter='+taskQuery+"^EQ", items: []};
t.items.unshift(link); // put 'View all requests' first

find_real_file.png

(The above script snippets are only for the RITM records; there are, of course, other parts of the script to handle the other task types -- incidents, CRs, etc.)

However, we discovered that some RITMs are not included because the user is the "Requested for" on the REQ, in the case where someone else opened an RITM on behalf of the user. We want to include those RITMs in the list as well.

I updated the script as follows.  The badge count works properly but I am unable to get the additional RITMs to display in the list when I click "View all requests." 

Updated script as follows...

For the badge watcher (this works):

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'sc_req_item','filter':'requested_for=' + u + '^ORopened_by=' + u + '^ORrequest.requested_for=' + u});

To get the list of RITMs (the menu displays the top 10 of all tasks by last modified date):

var z = new GlideRecord('sc_req_item');
z.addEncodedQuery('requested_for=' + gs.getUserID() + "^ORopened_by=" + gs.getUserID() + "^ORrequest.requested_for=" + gs.getUserID());
z.orderByDesc('sys_updated_on');
z.query();
totalItemsCount = totalItemsCount + z.getRowCount();
z.setLimit(max);
z.query();
while(z.next()){
  var a = {};
  $sp.getRecordValues(a, z, 'sys_id,number,sys_updated_on');
  a.short_description = z.cat_item.getDisplayValue();
  a.__table = z.getTableName();
  a.type = 'record';
  a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
  t.items.push(a);
}

And to create the URL that opens when the user clicks "View all requests" (this part does not work):

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe";
var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=list&table=task&view=portal&filter='+taskQuery+"^EQ", items: []};
t.items.unshift(link); // put 'View all requests' first

As you can see, the badge count changed to accommodate the updated query, but when I click the "View all requests" link, the count of the records returned does not match the badge count, and I do not find RITMs in the list that I should find.

find_real_file.png

 

I'm pretty sure it comes down to whether my syntax here is correct... or if this type of dot walking is supported in a scripted list. 

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe";

This is the query that is returned when I set the filter myself in the Service Portal and copy the URL.

find_real_file.png

This is the URL for the above filter:

https://<instance>/sp?id=list&table=task&view=portal&filter=sys_class_name%3Dsc_req_item%5Eref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORref_sc_request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe&spa=1&p=1&o=sys_updated_on&d=desc

I've also tried this...

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORrequest.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe";

URL becomes - https://<instance>/sp?id=list&table=task&view=portal&filter=sys_class_name%3Dsc_req_item%5Eref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORrequest.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe&spa=1&p=1&o=sys_updated_on&d=desc

...and that returns this filter when I open the resulting URL

find_real_file.png

Again, we are displaying multiple types of tasks so we are starting at the Task table to do the filtering.

I appreciate any help you can offer on this. Thank you!


Susan Williams, Lexmark
1 ACCEPTED SOLUTION

SusanWinKY
Kilo Sage

Solved, and posting the answer here in case it helps others.

I wasn't dot walking properly. I updated the query to:

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_req_item.request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe";

This is the resulting filter:

find_real_file.png

And the resulting URL:

https://<instance>/sp?id=list&table=task&view=portal&filter=sys_class_name%3Dsc_req_item%5Eref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORref_sc_req_item.request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe&spa=1&p=1&o=opened_at&d=desc


Susan Williams, Lexmark

View solution in original post

1 REPLY 1

SusanWinKY
Kilo Sage

Solved, and posting the answer here in case it helps others.

I wasn't dot walking properly. I updated the query to:

var taskQuery = "sys_class_name=sc_req_item^ref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_req_item.request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe";

This is the resulting filter:

find_real_file.png

And the resulting URL:

https://<instance>/sp?id=list&table=task&view=portal&filter=sys_class_name%3Dsc_req_item%5Eref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe%5EORref_sc_req_item.request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe&spa=1&p=1&o=opened_at&d=desc


Susan Williams, Lexmark