diff --git a/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/README.md b/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/README.md new file mode 100644 index 0000000000..3f0696495c --- /dev/null +++ b/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/README.md @@ -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. diff --git a/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/WeekendChecker.js b/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/WeekendChecker.js new file mode 100644 index 0000000000..b3b624bb92 --- /dev/null +++ b/Core ServiceNow APIs/GlideAjax/Check Weekend - Client Side/WeekendChecker.js @@ -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.'); + } + }); +}