Lock calendar day based on condition in record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 02:29 AM
Hi Everyone,
We have a requirement in our current project, that for one of the record producers, we have two variables i.e. Start date and end date.
We want those fields to be greyed out on basis of certain conditions.
For example: If A is selected from the dropdown (conditional third variable) in the above field then the Start date should have only Wednesday and Thursday selectable to user (lock other days).
Is it possible, if yes. please suggest how?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 07:36 AM
Hi @Ankur Bawiskar,
Thank you, response!
I have requirement like in record producer 3 variable (work schedule, start date and end date). work schedule is a dropdown variable (A, B, C).
If A is selected in this variable, then start date should be only Wednesday and Thursday selectable,
If B is selected, then start date should be only Sunday selectable,
if C is selected then start date should be only Tuesday and Wednesday selectable.
I really thank you in advance for your suggestions!
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 08:08 PM
you can use onChange on Start and end date and based on work schedule validate if the date selected is correct or not
what did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 08:54 PM
Hello @Ankur Bawiskar
Can you please provide examples or script if you have, that check day of selected date and work like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 04:26 AM
Something like this but please enhance
Script Include: It should be client callable
var SelectableDays = Class.create();
SelectableDays.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSelectableDays: function() {
var workSchedule = this.getParameter('work_schedule');
var startDate = this.getParameter('start_date');
var date = new GlideDateTime(startDate);
var dayOfWeek = date.getDayOfWeekLocalTime(); // 1 = Monday, 7 = Sunday
var validDays = [];
switch (workSchedule) {
case 'A':
validDays = [4, 5]; // Wednesday (4) and Thursday (5)
break;
case 'B':
validDays = [1]; // Sunday (1)
break;
case 'C':
validDays = [3, 4]; // Tuesday (3) and Wednesday (4)
break;
default:
break;
}
return validDays.includes(dayOfWeek).toString();
}
});
Client Script: Have similar for End Date
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var workSchedule = g_form.getValue('work_schedule');
var startDate = g_form.getValue('start_date');
// Call GlideAjax to get the selectable days
var ga = new GlideAjax('SelectableDays');
ga.addParam('sysparm_name', 'getSelectableDays');
ga.addParam('work_schedule', workSchedule);
ga.addParam('start_date', startDate);
ga.getXMLAnswer(function(response) {
var isValidDay = response == 'true';
if (!isValidDay) {
g_form.showFieldMsg('start_date', 'Selected date is not valid for the chosen work schedule.', 'error');
g_form.clearValue('start_date');
}
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader