Script to run on every page (Portal & Native UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 04:08 AM - edited 01-18-2023 04:32 AM
Hi,
I have a requirement for checking DOM elements for each page in ServiceNow instance. I can achieve that by using a Global UI Script for native ui and a footer widget in portal. But the thing is some of the pages in the native UI are hidden such as pages with $ sign. On those pages, UI script is not running. Do you know a method to run UI/Client scripts on those pages without breaking too many things? (https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0726313)
I have learned that UI scripts run only in gsft_main windows and in Polaris the requirement we have is becoming harder. We also want to include workspaces and other pages as well into this but we couldn't find a way to run any script on those pages as well. I wish we can inject our script in to the Unified Navigation and then let it work anywhere.
If you have any ideas, please share.
The goal in here is to capture every text/labels in the screen and analyze them once they the page is loaded. After some analysis manipulate those elements to change color or such.
Also additional question: How does the i18 Debugging work? Can we get those prefixes without enabling debugging from the server or client-side?
** Some example pages where ui scripts don't run.
Example 1 : Get the "CMDB Dashboard - CMDB View " text from the screen.
Example 2 : Get the "Recent " text from the screen.
And do some background functions etc.
Example 3: Get the "Important Actions " text from the workspace.
Without updating each workspace app from UI Builder and adding UX Client scripts to everyone. Also I think even with the UX Client scripts it is not possible to manipulate DOM for the UI Builder apps.
Reference : https://www.servicenow.com/community/developer-forum/is-it-possible-to-get-dom-element-via-client-sc...
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 02:42 PM - edited 01-18-2023 02:44 PM
The only way possible to modify elements on any page without updating each workspace app from UI Builder and adding UX Client scripts is to use a browser extension. (like what SN Util does).
What is your ultimate goal/use case here? Are you trying to apply a branding? change the look and feel?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 11:25 PM
Thank you Marc for your response, well the goal is to be able to get the texts from the page and analyze them then highlight the texts if they are somehow wrong or untranslated or such. So what about if just agree that we can't do it for the workspaces, is it possible for the other hidden UI pages like the ones in my examples without a browser extension?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:05 AM
I don't know of a way around this for workspaces or pages that aren't editable outside of Mark's browser extension option. Could you elaborate on your overall requirement here?
We have historically discouraged the use of global ui policies because of their high risk when it comes to upgrades, etc.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:48 AM
The requirement is to be able to capture any translatable text on the screen and compare it to the user's language. If they match or not. But It looks like an extension is the right way of this with integrated ServiceNow APIs.