Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Approvals count to display on portal home page

Karthik Reddy11
Tera Contributor

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

find_real_file.png

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.

3 REPLIES 3

SusanWinKY
Kilo Sage

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.

find_real_file.png


Susan Williams, Lexmark

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.***

We couldn't figure that out either, so we updated the script to display the accurate count.


Susan Williams, Lexmark