Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# ServiceNow Weekend Checker (Client-Side Utility)

A reusable client-side script to detect weekends (Saturday/Sunday) and modify ServiceNow form behaviour accordingly.

# Overview

This project contains a simple, reusable utility for determining if the current date (based on the user’s browser timezone) falls on a weekend.
It’s ideal for Client Scripts, Catalog Client Scripts, or Service Portal widgets.

# Features

- ✅ Lightweight — no dependencies
- ✅ Works across all client script contexts
- ✅ Includes helper method for automatic info messages

## ⚙️ Usage
Create the Script Include present in the WeekendChecker.js file
Use the Client-Side Script to call GlideAjax and determine if the day/date is a weekend or not.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//Script Include
var DateUtilityAjax = Class.create();
DateUtilityAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Returns true if the current server date is a weekend
isWeekend: function() {
var gdt = new GlideDateTime();
var dayOfWeek = gdt.getDayOfWeekLocalTime(); // Sunday = 1, Monday = 2, ..., Saturday = 7 in Servicenow
return (dayOfWeek === 1 || dayOfWeek === 7);
},

type: 'DateUtilityAjax'
});

//Client Script - GlideAjax
function onLoad() {
var ga = new GlideAjax('DateUtilityAjax');
ga.addParam('sysparm_name', 'isWeekend');

ga.getXMLAnswer(function(answer) {
var isWeekend = (answer === 'true');

if (isWeekend) {
g_form.addInfoMessage('Server reports it’s the weekend - some actions are restricted.');
} else {
g_form.addInfoMessage('Weekday detected - normal operations available.');
}
});
}
Loading