- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 12:37 PM
Hi,
I need to allow user to select date after 7 days but it should calculate only business days not weekend. In our project as per client we follow Friday, Saturday as weekend and I need to exclude Friday, Saturday. When user select date then it should calculate for Sunday, Monday, Tuesday, Wednesday, Thursday as business day.
Can you please help me with that.
Regards,
Nivedita
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 04:57 AM
it worked see
Script Include:
var ValidationUtils = Class.create();
ValidationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDate: function() {
var selected_date = new GlideDateTime(this.getParameter('sysparm_expectedDate'));
var requiredDate = new GlideDateTime(); // Todays Date
var businessDays = 7;
var daysAdded = 0;
while (daysAdded < businessDays) {
requiredDate.addDays(1); // Move to the next day
var dayOfWeek = requiredDate.getDayOfWeek(); // 1 = Sunday, 2 = Monday, ..., 7 = Saturday
if (dayOfWeek != 6 && dayOfWeek != 7) { // Exclude Friday (6) and Saturday (7)
daysAdded++;
}
}
var output = {};
if (selected_date.getDate() > requiredDate.getDate()) {
output.correctDateSelected = 'Yes';
} else {
output.correctDateSelected = 'No';
output.requiredDate = requiredDate.getDate().toString();
}
return JSON.stringify(output);
},
type: 'ValidationUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('my_datetime');
var validateSelectedDate = new GlideAjax('global.ValidationUtils');
validateSelectedDate.addParam('sysparm_name', 'validateDate');
validateSelectedDate.addParam('sysparm_expectedDate', g_form.getValue('my_datetime')); //Replace your date time variable
validateSelectedDate.getXMLAnswer(function getExpectedDate(answer) {
var validatedOutput = JSON.parse(answer);
if (validatedOutput.correctDateSelected == 'No') {
g_form.showFieldMsg('my_datetime', 'kindly select date after ' + validatedOutput.requiredDate.toString(), 'error');
}
});
//Type appropriate comment here, and begin script below
}
Output:
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-24-2025 10:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 10:20 PM
@niveditakumari Share screenshot of error and scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 12:05 AM
Hi @SANDEEP28,
I'm getting below error :
Please find attached script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 12:08 AM
Hi @SANDEEP28,
When I'm submitting that request it is showing me above error and I'm able to submit that request.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 01:03 AM
Hi @Ankur Bawiskar,
I'm getting error when submitting request.
Can you please help me with above script.
Regards,
Nivedita