
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2017 08:21 AM
At the top of the menu in the Service Portal is My Requests which show incidents and Requests. How can I modify the default code which is below to show incidents and requested items instead. My requirements are to show them where they can see the communication and since all communication goes thought the Requested item I need to display that instead.
// 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=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, 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 requests'), type: 'link', href: '?id=requests', items: []};
t.items.unshift(link); // put 'View all requests' first
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2017 08:39 AM
Change line 16 to:
t.record_watchers.push({'table':'sc_req_item','filter':'active=true^request.requested_for=' + u});
Change line 57-81 to:
var z = new GlideRecord('sc_req_item');
z.addActiveQuery();
z.addQuery('request.requested_for', gs.getUserID());
z.orderByDesc('sys_updated_on');
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() || z.getDisplayValue("short_description");
a.__table = z.getTableName();
a.type = 'record';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2017 08:39 AM
Change line 16 to:
t.record_watchers.push({'table':'sc_req_item','filter':'active=true^request.requested_for=' + u});
Change line 57-81 to:
var z = new GlideRecord('sc_req_item');
z.addActiveQuery();
z.addQuery('request.requested_for', gs.getUserID());
z.orderByDesc('sys_updated_on');
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() || z.getDisplayValue("short_description");
a.__table = z.getTableName();
a.type = 'record';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2017 08:54 AM
Thanks Nia I was so close but now that I'm looking at this code it seems so simple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2017 04:14 PM
Thanks Nia for this solution, I was simply missing the request for request.requested_for in my query. Saved me about an hour of a headache there.
I have a question based off of this - how do I modify the link so clicking one of these items takes me to the RITM page for the corresponding item? I currently get to a page with a slew of errors when clicking on one of those items, and am failing to see in the code (or other location) where this is set for where clicking one of these items navigates to.
Thanks!
Edit:
Nevermind! Forgot to query for the sys_id in my code. Added it as it shows below and everything works properly now. Ironically enough, was just an oversight from missing a piece in your original example.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:23 PM
Hello Nia,
Now they want to display the REQ number by the RITM number. Any thoughts on what I need to add to display the REQ # as well?