Skip to content

Commit 599f55e

Browse files
authored
Announcement banner (#2205)
* Create annoucement_banner.js * Create README.md
1 parent 74f8b02 commit 599f55e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This UI Script is used to inject a custom, highly visible, and persistent notification banner across the top of the entire ServiceNow platform interface.
2+
3+
It is ideal for communicating critical, non-transactional system messages such as scheduled maintenance, major outages, or company-wide policy announcements.
4+
5+
The key feature of this banner is that it is dismissible, and it uses a User Preference to ensure that once a user closes a specific version of the announcement
6+
7+
The Reason to use this is , Announcements Banner Module Sometimes Loads Slower or Doesnt trigger the notification banner , instead this scripts all the time,if user is logged in
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(function() {
2+
var BANNER_TEXT = ' **SYSTEM ALERT:** Scheduled maintenance for all services will occur this Saturday from 1 AM to 4 AM UTC. Expect minor downtime. 🚨';
3+
var BANNER_BG_COLOR = '#ffcc00'; // Warning yellow
4+
var BANNER_TEXT_COLOR = '#333333';
5+
6+
// Check if the user has already dismissed this version of the banner
7+
var isDismissed = (g_preference.get(PREF_KEY) === 'true');
8+
9+
if (isDismissed) {
10+
return;
11+
}
12+
var banner = document.createElement('div');
13+
banner.setAttribute('id', 'global_announcement_banner');
14+
banner.innerHTML = BANNER_TEXT;
15+
banner.style.cssText = [
16+
'position: fixed;',
17+
'top: 0;',
18+
'left: 0;',
19+
'width: 100%;',
20+
'padding: 10px 40px 10px 15px;', // Added padding on the right for the close button
21+
'background-color: ' + BANNER_BG_COLOR + ';',
22+
'color: ' + BANNER_TEXT_COLOR + ';',
23+
'z-index: 10000;', // High z-index to ensure it sits on top of everything
24+
'text-align: center;',
25+
'font-weight: bold;',
26+
'box-shadow: 0 2px 5px rgba(0,0,0,0.2);'
27+
].join('');
28+
var closeButton = document.createElement('span');
29+
closeButton.innerHTML = '×'; // Times symbol
30+
closeButton.style.cssText = [
31+
'position: absolute;',
32+
'top: 50%;',
33+
'right: 15px;',
34+
'transform: translateY(-50%);',
35+
'font-size: 20px;',
36+
'cursor: pointer;',
37+
'font-weight: normal;',
38+
'line-height: 1;'
39+
].join('');
40+
41+
closeButton.onclick = function() {
42+
// Remove the banner from the DOM
43+
banner.remove();
44+
45+
// Set the User Preference so the banner stays dismissed across sessions
46+
g_preference.set(PREF_KEY, 'true');
47+
};
48+
banner.appendChild(closeButton);
49+
document.body.appendChild(banner);
50+
51+
})();

0 commit comments

Comments
 (0)