Catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2025 10:53 AM
I need help creating a catalog client script with these functions:
The field name is date_of_movement
If the current date is between the 1st and the 19th, the transaction date can be any date within the current month. (Limited to business days)
If the current date is greater than or equal to the 20th, the transaction date can only be from the month following the current month onwards. (Limiting to business days)
Translated with DeepL.com (free version)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2025 06:05 PM
Hi @larissaribe ,
By writing a catalog onChange client script on date_of_movement that computes todaya date, checks whether the day is ≤ 19 or ≥ 20, and depending on that either restricts the selected date to business days within the current month or only dates from the next month onward (while rejecting weekends), and additionally include a matching onSubmit script to enforce the same logic before submission so invalid dates are blocked even if the onChange check is bypassed...
Let me know if you need code for this...!!
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2025 08:16 PM
Hi @larissaribe ,
try this catalgoue client script simple logics
function onLoad() {
// your field name and gets iits control
var name = 'date_of_movement';
var control = g_form.getControl(name) || g_form.getControl('variables.'+name);
//alert("control == "+control);
var today = new Date();
var d = today.getDate();
//checks its weekly
function isWeekday(dt){ var day = dt.getDay(); return day !== 0 && day !== 6; }
// get first weekday of month
var first = new Date(today.getFullYear(), today.getMonth(), 1);
while(!isWeekday(first)) first.setDate(first.getDate()+1);
//checking date in betn 1 to 19 or not
if (d >= 1 && d <= 19) {
// allow this month's business days only
var last = new Date(today.getFullYear(), today.getMonth()+1, 0);
while(!isWeekday(last)) last.setDate(last.getDate()-1);
control.setAttribute('min', first.toISOString().slice(0,10));
control.setAttribute('max', last.toISOString().slice(0,10));
g_form.showFieldMsg(name, 'Allowed: business days this month', 'info', false);
} else {
// allow from first business day of next month onwards
var nextFirst = new Date(today.getFullYear(), today.getMonth()+1, 1);
while(!isWeekday(nextFirst)) nextFirst.setDate(nextFirst.getDate()+1);
control.setAttribute('min', nextFirst.toISOString().slice(0,10));
control.removeAttribute('max');
g_form.showFieldMsg(name, 'Allowed: business days from next month onwards', 'info', false);
}
}
Let me know if this not working or share sceenshorts of error you facing
or let me know if you want onchange or onsubmit client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2025 10:03 PM
so what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I need the script, please
