Help with Scripted List on Employee Center Menu

kmolson73
Tera Expert

After moving from Service Portal to the Employee Center, our users are really missing the drop-down list of their Issues & Requests that was in the old menu. I tried replicating the SP scripted list but it doesn't seem to work. I did find other community posts about this and tried their recommendations but it's still not working. We have a lot of custom tables but I can't even get it to show the requests and incidents correctly. I have setup the Advanced Portal Navigation and am using that to call the scripted list from my menu and had updated my script where I had short description to name and I do get my one request item to show up but nothing happens when I click on it and my open incident doesn't show up in the list although it appears there is something there. I did check the Employee Center Navigation widget and it is looking for name in the script. Snapshot attached of what the menu looks like on Employee Center. Any ideas are welcomed. 

 

Type: Scripted List

Condition: gs.isLoggedIn()

Server Script:

// maximum number of entries in this Menu
var max = 30;

var dataObj = data;
dataObj.items = [];
dataObj.count = 0;
dataObj.showAlways = true;

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

// use record watchers to tell header when to update dropdown counts
dataObj.record_watchers = [];
dataObj.record_watchers.push({'table':'service_task','filter':'active=true^opened_by=' + u});
dataObj.record_watchers.push({'table':'incident','filter':'active=true^caller_id=' + u});
dataObj.record_watchers.push({'table':'sc_request','filter':'active=true^requested_for=' + u});
dataObj.record_watchers.push({'table':'sc_req_item','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();
dataObj.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();
dataObj.items.push(a);
}


var z = new GlideRecord('sc_req_item');
z.addActiveQuery();
z.addEncodedQuery('active=true^cat_item!=e402c9384f185700539085c98310c7cd^cat_item!=bcf1fc891bab330053b3a9ffbd4bcb02^cat_item!=0e256df21be64850bf07da4cbc4bcb58^cat_item!=0c396cc91b6b330053b3a9ffbd4bcbdb^cat_item!=5af3f04d1bab330053b3a9ffbd4bcb35^cat_item!=b5c3d4280fd112406f23ba8ce1050e1a^cat_item!=e402c9384f185700539085c98310c7cd^cat_item!=cca3c76d4f101b00539085c98310c762^cat_item!=79a44a0e4f6bc740539085c98310c73c^request.requested_for=' + u + '^ORopened_by=' + u);
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.name = z.cat_item.getDisplayValue() || z.getDisplayValue("short_description");
a.__table = z.getTableName();
a.type = 'request';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
dataObj.items.push(a);
}


dataObj.items.sort(function(a, b) {
return b.sortOrder - a.sortOrder;
});
dataObj.items = dataObj.items.slice(0, max); // Only want first 30
dataObj.count = dataObj.items.length;


var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=requests', items: []};
dataObj.items.unshift(link); // Put 'View all requests' first

 

 

 

2 REPLIES 2

tejasadinen
ServiceNow Employee
ServiceNow Employee

Thank you Teja, I will give that article and the other information you gave me a try.