- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 03:17 AM
The date field should not allow users to fill less than 24 hrs from the current date and it should follow a defined schedule
For example Schedule: Mon-Fri (8:00-19:00)Business hours
it should throw an error if the date is less than 24 hrs or out of business hours.
Looking for help.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 08:54 PM
Hi,
is script include client callable?
is the function being called properly?
share logs for this
var ajaxDateDiff = Class.create();
ajaxDateDiff.prototype = Object.extendsObject(AbstractAjaxProcessor, {
check5Days: function () {
var answer;
var valid = new GlideDateTime();
valid.setDisplayValue(this.getParameter('sysparm_date'));
gs.info('User value->' + valid);
var schedule = new GlideSchedule('377f5e51db2e851040d8176a489619cc');
var inSchedule = schedule.isInSchedule(valid);
gs.info("Is in schedule->" + inSchedule);
if (!inSchedule)
{
answer = 'false';
}
else
{
answer = 'true';
}
return answer;
},
});
Regards
Ankur
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-30-2022 09:43 PM
Seems due to date format of user
Can you try to change user date format to YYYY-MM-DD and check once
Regards
Ankur
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-30-2022 09:54 PM
Hi Ankur,
Changed the format to YYYY-MM-DD . but No response still the same.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 10:27 PM
the logic I shared should work
Are you in scoped app?
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-31-2022 01:50 AM
Hi Ankur
I made the changes to the script include it worked for me.
var outofbussHours = Class.create();
outofbussHours.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDays: function() {
var answer = "";
var valid = this.getParameter('sysparm_date');
valid.setDisplayValue(this.getParameter('sysparm_date'));
--->var date = new GlideDateTime('valid');
--->date.setDisplayValue(this.getParameter('sysparm_date'));
// gs.log('user value->' + date);
var schedule = new GlideSchedule('377f5e51db2e851040d8176a489619cc');
//schedule.get("377f5e51db2e851040d8176a489619cc");
gs.log('schedule selected->' + schedule);
//var schedule = new GlideSchedule('377f5e51db2e851040d8176a489619cc');
var inSchedule = schedule.isInSchedule(date);
gs.log('Is in schedule->' + inSchedule);
if (!inSchedule) {
answer = false;
} else {
answer = true;
}
return answer;
},
});
works perfectly for business hours within schedule
Thanks for your support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 02:14 AM
Glad to know.
Please mark my response as correct and close the thread
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader