There are a few different methods to always show approvals or requests in the top menu bar. Some involve cloning the header widget, adjusting angular templates, and even more creative designs.
I like the simplicity of this design below. You just add a couple menu items and some scripts, and you don’t even have to adjust a widget.
It effectively just takes to the page instead of a scripted list when there are no requests/approvals.
Code
Approvals
Script Include
Name: hasApprovals
API Name: global.hasApprovals
Application: Global
Accessible from: All application scopes
Active: true
Script:
function hasApprovals() {
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('approver', '=', gs.getUserID());
grApproval.addQuery('state', '=', 'requested');
grApproval.query();
return grApproval.hasNext();
}
Menu Item
Label: Approvals
Parent Menu: SP Header Menu
Type: Page
Order: 400
Page: approvals
Condition: gs.isLoggedIn() && gs.getUser().hasRole('approver_user') && !hasApprovals()
Requests
Note: This is no longer needed in ServiceNow Orlando, as menu item for Requests always shows, regardless of whether you have them or not.
SCRIPT INCLUDE
You may need to adjust this script include depending on what records you display in the service portal.
Name: hasRequests
API Name: global.hasRequests
Application: Global
Accessible from: All application scopes
Active: true
Script:
function hasRequests() {
var recFound = false;
var grST = new GlideRecord('service_task');
grST.addActiveQuery();
grST.addQuery('opened_by', gs.getUserID());
grST.query();
var hasST = grST.hasNext();
var grIncident = new GlideRecord('incident');
grIncident.addActiveQuery();
grIncident.addQuery('caller_id', gs.getUserID());
grIncident.query();
var hasIncident = grIncident.hasNext();
var grRequest = new GlideRecord('sc_request');
grRequest.addActiveQuery();
grRequest.addQuery('requested_for', gs.getUserID());
grRequest.query();
var hasRequest = grRequest.hasNext();
if (hasST || hasIncident || hasRequest) {
recFound = true;
}
return recFound;
}
MENU ITEM
Label: Requests
Parent Menu: SP Header Menu
Type: Page
Order: 400
Page: requests
Condition: gs.isLoggedIn() && !hasRequests()