- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 06:26 AM
Hi,
I am in a scenario where I should i be allowed to select next 15 business days from today. I tried getting some help from community, but it didn't work. Kindly help.
(function executeRule(current, previous /*null when async*/ ) {
var schId = "090eecae0a0a0b260077e1dfa71da828";
var sch = new GlideSchedule(schId);
var now = new GlideDateTime();
var next15Days = sch.add(now, 15, "business");
var dateThreshold = new GlideDateTime(next15Days).getDate();
if (current.desired_completion_date < dateThreshold) {
gs.addErrorMessage("Date must be after 15 business days.");
current.setAbortAction(true);
}
})(current, previous);
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 06:30 AM
you should use onChange catalog client script rather than BR
check this and enhance
Variable Date no less than 5 business days
Auto-populating and validating date fields
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-21-2025 07:16 AM
Hi Dave - 43200 is how many seconds are in 12 hours(the schedule of 8-8 is 12 hour business days).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 06:30 AM
you should use onChange catalog client script rather than BR
check this and enhance
Variable Date no less than 5 business days
Auto-populating and validating date fields
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
01-15-2025 06:34 AM
I will try this now Ankur.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 06:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 07:00 AM
This is the final code which is updated to work for 15 Business Days for 8-5 excluding weekends.
THERE IS NOTHING GREAT ABOUT ME. All respect to @booher04
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('date_Class');
ga.addParam('sysparm_name', "date_Function");
ga.addParam('sysparm_date', g_form.getValue('desired_completion_date'));
ga.getXMLAnswer(function(answer) {
if (answer == 'true') {
alert('Please select date after 15 business days');
g_form.clearValue('desired_completion_date');
}
});
}
var date_Class = Class.create();
date_Class.prototype = Object.extendsObject(AbstractAjaxProcessor, {
date_Function: function() {
var dateSelected = this.getParameter('sysparm_date');
var nowDateTime = new GlideDateTime();
var days = 15;
var dur = new GlideDuration(days * 32400 * 1000);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var finalTime = schedule.add(nowDateTime, dur, '');
var updatedGdt = new GlideDateTime(dateSelected);
var finalTimeGdt = new GlideDateTime(finalTime);
if (updatedGdt < finalTimeGdt) {
return 'true';
}
return 'false';
},
type: 'date_Class'
});
Regards
Suman P.