- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 02:54 AM
Hi all
We've got a requirement for the ServicePortal to show users closed as well as their open incidents & requests.
The list of these comes from a Header Menu scripted list called 'My Calls'
Looking at the code, is it as simple as removing the highlighted text, or something a bit cleverer?
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 06:12 AM
Dont remove
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});
replace them with
t.record_watchers.push({'table':'incident','filter':'caller_id=' + u});
t.record_watchers.push({'table':'sc_request','filter':'requested_for=' + u});
and in places where you have used addActiveQuery(), add an "//" before them
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 05:03 AM
Thanks for the replies. Here's the entire code
// maximum number of entries in this Menu
var max = 5;
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=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.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.addActiveQuery();
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.addActiveQuery();
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, ritm, '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 = ritm.getTableName();
a.type = 'request';
a.sortOrder = ritm.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 calls'), type: 'link', href: '?id=requests', items: []};
t.items.unshift(link); // put 'View all requests' first
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 05:12 AM
In the script remove both your highlighted text and remove the "addActiveQuery()" from the rest of the scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 05:21 AM
Thinking about this, my question would be: is it a good idea to include closed items in the list?
Displaying closed records in the list will mean that the list will never shrink but keep growing. Wouldn't it be better to just include a list of the closed records on the "View all" page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 05:26 AM
Hi Chris
Thanks for the help here. I fear I may be out of my depth somewhat.
I was presuming that amending this setting would continue to display 5 as a maximum, but the closed records would also be in the 'view all' page.
Is this not also the code for the 'view all' screen?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 05:43 AM
That's correct, it will not show more than 5 entries