- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 02:11 PM
From within the Service Portal, if I click on Requests from the top nav bar and select 'View all requests,' I am taken to the request page that displays my open incidents and requests. Currently, the 'My Incidents' section sorts by the sys_updated_on field. I want this list to sort by the sys_created_on field. I thought I could achieve this by editing the Requests menu item from the 'SP Header Menu' parent menu, but my edits had no effect. What am I doing wrong or am I approaching this incorrectly?
- Go to Service Portal > Menus
- Open menu instance with the Title: SP Header Menu
- In the Menu Items related list, select Requests
Here are my edits to the Server Script field with the OOB code commented out:
// 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.orderByDesc('sys_created_on');
st.setLimit(max);
st.query();
while (st.next()) {
var a = {};
//$sp.getRecordValues(a, st, 'short_description,sys_id,number,sys_updated_on');
$sp.getRecordValues(a, st, 'short_description,sys_id,number,sys_created_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();
a.sortOrder = st.sys_created_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.orderByDesc('sys_created_on');
z.setLimit(max);
z.query();
while (z.next()) {
var a = {};
//$sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on');
$sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_created_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();
a.sortOrder = z.sys_created_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.orderByDesc('sys_created_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');
$sp.getRecordValues(a, z, 'sys_id,number,sys_created_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();
a.sortOrder = z.sys_created_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.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 10:18 PM
Hi Troy,
Under Service Portal --> Widget Instances search for your instance name 'My Open Incident' under title:
Try adding "Order by" and "Order Direction" in your widget instance form. Then you can set the order via the form for that instance. You may need to configure form layout to get order by field:
Thanks
Shruti
If the reply was informational, please like, mark as helpful or mark as correct!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 10:18 PM
Hi Troy,
Under Service Portal --> Widget Instances search for your instance name 'My Open Incident' under title:
Try adding "Order by" and "Order Direction" in your widget instance form. Then you can set the order via the form for that instance. You may need to configure form layout to get order by field:
Thanks
Shruti
If the reply was informational, please like, mark as helpful or mark as correct!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:51 AM
Thank you, Shruti. This is exactly what I needed.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 12:43 PM
Hello Shruti,
I have similar case where we have custom widget that displays list of incidents and request based on filter condition active is true and caller is dynamic.
When some one selects on menu item tickets it will show open incidents which is working as expected. how ever list displays oldest tickets first and then new ones in bottom.
Your recommendation might work when some one is using OOB "Simple list" and "data table" widget.
By any chance did you encountered this issue with customized "data table" widget.
can you provide some solution one sorting based on created for custom widgets.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 12:55 PM