The CreatorCon Call for Content is officially open! Get started here.

Display Approval count when approval is requested.

Reddy
Kilo Sage

Hello,

I want the "Approvals" menu item to be shown at all times, and I want the approval count to be visible when approval is requested. The OOB menu item code is shown below.

find_real_file.png

// 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();
}

1 ACCEPTED SOLUTION

Reddy
Kilo Sage

In this thread, I discovered the correct answer.

https://community.servicenow.com/community?id=community_question&sys_id=9272c7f1dbfa53805ed4a851ca961949

View solution in original post

2 REPLIES 2

Sai Kumar B
Mega Sage

Hi,

You can increase the max value in the code.

Reddy
Kilo Sage

In this thread, I discovered the correct answer.

https://community.servicenow.com/community?id=community_question&sys_id=9272c7f1dbfa53805ed4a851ca961949