Skip to content

Commit 69d368c

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into improve-ci-classes-readme
2 parents 516c790 + 5bb9298 commit 69d368c

File tree

12 files changed

+337
-0
lines changed

12 files changed

+337
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading) {
3+
return;
4+
}
5+
6+
var maxChars = 100;//count of charaters
7+
var currentLength = newValue.length;
8+
9+
// Clear previous messages
10+
g_form.clearMessages();
11+
12+
// Show info message
13+
g_form.addInfoMessage('Character count: ' + currentLength + ' / ' + maxChars);
14+
15+
if (currentLength > maxChars) {
16+
// Show error message
17+
g_form.addErrorMessage('Character limit exceeded! Please shorten your text.');
18+
g_form.showFieldMsg('short_description', 'Too many characters!', 'error');
19+
20+
// Make field mandatory to block submission
21+
g_form.setMandatory('short_description', true);
22+
} else {
23+
// Remove mandatory if valid
24+
g_form.setMandatory('short_description', false);
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This onChange Catalog Client Script displays the current character count for a text field and enforces a maximum limit by showing error messages and making the field mandatory to prevent form submission when exceeded.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Table: Time Worked [task_time_worked]
2+
Type: onsubmit
3+
4+
#Objective :
5+
Ensure that time entries (represented by the work_date field) are not submitted after 8:00 PM CST on two key dates:
6+
The 16th of the month and The last day of the month
7+
If a user tries to submit time for a current or past date after the cut-off time, the submission is blocked and a clear error message is displayed.
8+
9+
#Business Scenario
10+
Imagine a consulting firm where employees log billable hours against customer cases. There are internal controls in place that lock the timekeeping system after a certain cut-off time to ensure accurate payroll and billing.
11+
12+
The finance department requires that:
13+
On the 16th and last day of each month, submissions must be in before 8:00 PM CST.
14+
If employees miss the deadline, they can only log time for future dates (not today or the past).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function onSubmit() {
2+
// Cutoff time for submission in CST.
3+
var cutoffTime = "20:00:00";
4+
5+
// Get the current date and time in CST
6+
var currentDate = new Date();
7+
var currentCSTDate = new Date(
8+
currentDate.toLocaleString("en-US", {
9+
timeZone: "America/Chicago"
10+
})
11+
);
12+
13+
// Get time from current CST date
14+
var currentCSTTime = currentCSTDate.toTimeString().substring(0, 8);
15+
16+
// Get last day of the month
17+
var dayOfMonth = currentCSTDate.getDate();
18+
var lastDayOfMonth = new Date(
19+
currentCSTDate.getFullYear(),
20+
currentCSTDate.getMonth() + 1,
21+
0
22+
).getDate();
23+
24+
if ((dayOfMonth === 16 || dayOfMonth === lastDayOfMonth) && currentCSTTime > cutoffTime) {
25+
var workDate = g_form.getValue("work_date");
26+
27+
if (workDate) {
28+
var formattedWorkDate = new Date(workDate + "T00:00:00");
29+
// If work_date is on or before current date, block submission
30+
if (formattedWorkDate <= currentCSTDate) {
31+
g_form.addErrorMessage(
32+
"The time period closed for time submission at 8:00 PM CST. Time must be billed in the next time period." + ": " + lastDayOfMonth
33+
);
34+
return false;
35+
}
36+
}
37+
}
38+
return true;
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Table: sn_customerservice_case
2+
Type: OnChange
3+
Field: Priority
4+
5+
Use Case:
6+
Make additional comments mandatory on priority change for the case table.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') {
3+
return;
4+
}
5+
if ((!g_form.isNewRecord()) && (newValue != oldValue)) {
6+
g_form.setMandatory('comments', true);
7+
g_form.addErrorMessage('Additional comment required when changing Priority.');
8+
} else {
9+
g_form.setMandatory('comments', false);
10+
}
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+
})();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
parseExcel: function() {
2+
var attachSysId = this.getParameter('sysparm_id');
3+
var attachment = new GlideSysAttachment();
4+
var parser = new sn_impex.GlideExcelParser();
5+
var mrvsArray = [];
6+
// get content of the attachment
7+
var content = attachment.getContentStream(attachSysId);
8+
parser.parse(content);
9+
// Iterate through each row after header. Return false if row doesn't exist
10+
while (parser.next()) {
11+
// get content of the row
12+
var row = parser.getRow();
13+
//push the object with key same as variable name in the MRVS.
14+
var obj = {};
15+
obj.employee_id = row['Id'];
16+
obj.employee_name = row['Name'];
17+
mrvsArray.push(obj);
18+
}
19+
return JSON.stringify(mrvsArray);
20+
},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This script allows to parse the excel file attached to the attachment variable and populate the MRVS present in the
2+
catalog item / record producer.
3+
Use this script in a client-callable script include along with an onChange client script on the attachment variable.
4+
5+
When a file is uploaded as an attachment, it's metdata is stored in the sys_attachment table and sys_attachment_doc contains
6+
the actual binary content.
7+
8+
**getContentStream()** converts the binary content in a way so that it can be parsed by GlideExcelParser API.
9+
10+
**Example used-**
11+
12+
The excel has two columns "Id" and "Name" to store employee details. MRVS also has the variable name as "employee_id" and "employee_name".
13+
14+
15+
16+

0 commit comments

Comments
 (0)