Skip to content

Commit 0b12366

Browse files
authored
ServiceNow Weekend Checker (Client-Side Utility) (#2529)
* Create WeekendChecker.js * Update WeekendChecker.js * Create README.md
1 parent 70518c2 commit 0b12366

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# ServiceNow Weekend Checker (Client-Side Utility)
3+
4+
A reusable client-side script to detect weekends (Saturday/Sunday) and modify ServiceNow form behaviour accordingly.
5+
6+
# Overview
7+
8+
This project contains a simple, reusable utility for determining if the current date (based on the user’s browser timezone) falls on a weekend.
9+
It’s ideal for Client Scripts, Catalog Client Scripts, or Service Portal widgets.
10+
11+
# Features
12+
13+
- ✅ Lightweight — no dependencies
14+
- ✅ Works across all client script contexts
15+
- ✅ Includes helper method for automatic info messages
16+
17+
## ⚙️ Usage
18+
Create the Script Include present in the WeekendChecker.js file
19+
Use the Client-Side Script to call GlideAjax and determine if the day/date is a weekend or not.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//Script Include
2+
var DateUtilityAjax = Class.create();
3+
DateUtilityAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
4+
//Returns true if the current server date is a weekend
5+
isWeekend: function() {
6+
var gdt = new GlideDateTime();
7+
var dayOfWeek = gdt.getDayOfWeekLocalTime(); // Sunday = 1, Monday = 2, ..., Saturday = 7 in Servicenow
8+
return (dayOfWeek === 1 || dayOfWeek === 7);
9+
},
10+
11+
type: 'DateUtilityAjax'
12+
});
13+
14+
//Client Script - GlideAjax
15+
function onLoad() {
16+
var ga = new GlideAjax('DateUtilityAjax');
17+
ga.addParam('sysparm_name', 'isWeekend');
18+
19+
ga.getXMLAnswer(function(answer) {
20+
var isWeekend = (answer === 'true');
21+
22+
if (isWeekend) {
23+
g_form.addInfoMessage('Server reports it’s the weekend - some actions are restricted.');
24+
} else {
25+
g_form.addInfoMessage('Weekday detected - normal operations available.');
26+
}
27+
});
28+
}

0 commit comments

Comments
 (0)