Approvals count to display on portal home page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2022 01:23 AM
Hi all
In portal page there are more than 30 approvals
so I want to display '30+' if there are more than 30 approvals
can you help me with this
widget approval script:
Server script:
---------------------------------------------------------------------------------------------
// only show 30 in header menu dropdown
var max = 30;
var t = data;
t.items = [];
t.count = 0;
var u = getMyApprovals();
// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'sysapproval_approver','filter':'approverIN' + u.toString() + '^state=requested'});
var z = new GlideRecord('sysapproval_approver');
z.addQuery("approver", u);
z.addQuery("state", "requested");
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
var link = {};
link.title = gs.getMessage('View all approvals');
link.type = 'link';
link.href = '?id=approvals';
link.items = [];
t.items.push(link);
while (z.next()) {
var a = {};
var rec = getRecordBeingApproved(z);
if (!rec.isValidRecord()) // nothing being approved - hmmm
continue;
a.short_description = rec.short_description + "";
if (rec.getRecordClassName() == "sc_request") {
var items = new GlideRecord("sc_req_item");
items.addQuery("request", rec.getUniqueValue());
items.query();
if (items.getRowCount() > 1)
a.short_description = items.getRowCount() + " requested items";
else if (items.getRowCount() == 1) {
items.next();
a.short_description = items.getValue("short_description");
}
}
$sp.getRecordValues(a, z, 'sys_id,sys_updated_on');
a.number = rec.getDisplayValue();
a.__table = z.getRecordClassName();
a.type = 'approval';
t.items.push(a);
t.count++;
}
function getRecordBeingApproved(gr) {
if (!gr.sysapproval.nil())
return gr.sysapproval.getRefRecord();
return gr.document_id.getRefRecord();
}
-----------------------------------------------------------------------------------------------
can you help me with this
Instance link:
https://instance id.service-now.com/sp_rectangle_menu_item.do?sys_id=864aed00d7200200a9ad1e173e24d475&sysparm_record_target=sp_rectangle_menu_item&sysparm_record_row=9&sysparm_record_rows=11&sysparm_record_list=sp_rectangle_menu%3Dd150fd31cb10020000f8d856634c9ce6%5EORDERBYorder
Thanks,
karthik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2022 02:53 PM
Karthik, we did this recently. We had to have a separate count of all the items and then use that instead of the max #. The menu we have displays lots of record types and is quite lengthy, so it's difficult to explain in a quick reply here. So I've attached our Request History menu as XML. Hoping it helps.
The variable that counts the total is:
var totalItemsCount = 0;
Look for that variable used throughout the script.
This is what it looks like in our service portal.
Susan Williams, Lexmark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-13-2022 03:36 PM
Hi Susan,
That variable only take integers it doesnt let us add '+' after the number
if you know how to do that do let us know here.
Thanks,
Yousaf
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-14-2022 11:01 AM
We couldn't figure that out either, so we updated the script to display the accurate count.
Susan Williams, Lexmark