
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 10:47 AM
Has anybody tackled adding a link to the service portal in the user menu after upgrading to San Diego?
The old method on UI16 was to use an AngularJS selector and insert an html element into the menu, but that method doesn't seem to work now. I don't know enough about the new framework and React to know if there's an equivalent React method that could be used.
Screenshot of menu to avoid confusion as to which menu I'm talking about.
Solved! Go to Solution.
- Labels:
-
UI Framework Next Experience

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 02:16 PM
Here's the solution I came up with, which is not supported in any way by ServiceNow, of course. (They told me so in the support case I opened). This is a global UI script, just like the previous solution with UI16.
Having document objects nested in multiple shadow DOMs makes this a little more complicated than the old solution.
One improvement this needs is to stop observing the "dom:loaded" event after this is run in order to prevent this from being run more than one time. Currently it will re-run every time a glideForm or glideList is loaded. I was not able to find a solution for this, so any suggestions for improvement would be welcome.
$(document).observe('dom:loaded', function() {
try {
var text = getMessage('Open Service Portal') + '';
// get document object
// jQuery selector used to avoid a health scan flag
// addressing the top object is necessary because the scoped window and document objects
// in this UI script are within a shadow DOM and is not an ancestor of "macroponent"
var d = $(top).window.document;
// get shadow DOM of header
var headerRoot = d.querySelector('macroponent-f51912f4c700201072b211d4d8c26010')
.shadowRoot.querySelector('sn-polaris-layout')
.shadowRoot.querySelector('sn-polaris-header')
.shadowRoot;
// prevent more than one portal link from being added
if (headerRoot.querySelector('.custom-service-portal-link')) return;
// get user menu component
var menu = headerRoot.querySelector('.user-menu-controls');
// build button element and necessary child elements for new link
var button = d.createElement('button');
button.className = "user-menu-button keyboard-navigatable polaris-enabled custom-service-portal-link";
button.addEventListener('click', goToPortal);
var div = d.createElement('div');
div.className = "user-menu-label polaris-enabled";
var icon = d.createElement('now-icon');
icon.className = "user-menu-icon polaris-enabled";
icon.setAttribute("icon", "square-share-fill");
button.append(div);
div.append(icon);
div.append(text);
// add button element to user menu
menu.append(button);
} catch (e) {}
function goToPortal() {
$(top).window.location.href = '/sp';
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 02:33 PM
Disclaimer: I suspect this has a high probability of breaking after upgrades.