- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 02:53 AM
Hi,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var seldate=g_form.getValue('date');
var objdate=new Date(seldate);
var selday=objdate.getDay();
alert(selday);
if(selday==0||selday==6)
{
alert('select business day');
g_form.setValue('date','');
}
}
but i am getting "NaN " value in alert.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 06:50 PM
did you try with the code which i have posted ?
Updated Code:
var df = g_form.getValue('u_date');
var op=df.split('/');
var ress=op[2]+'/'+op[1]+'/'+op[0];
var objdate=new Date(ress);
alert(objdate);
var selday=objdate.getDay();
var res = parseInt(selday);
alert(res);
if(res==0||res==6)
{
alert('select business day');
}
Change the field value. if you have a data/time type field then you can follow the same split() to make your data format like yyyy-MM-dd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 03:26 AM
example script Date validation excluding weekends
Script Include:
var dateTime = Class.create();
dateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
dateTimeExcludingHolidays : function(){
//var my_end_gdt=this.getParameter('sysparm_nam');
var ap=this.getParameter('sysparm_nam');
var my_start_gdt = new GlideDateTime();
var my_end_gdt = new GlideDateTime();
my_end_gdt.setValue(ap);
var days_between = parseInt(gs.dateDiff(my_start_gdt.getDate(),my_end_gdt.getDate()));
var day_of_the_week = my_start_gdt.getDayOfWeekUTC();
var number_of_weekends = parseInt((days_between+day_of_the_week)/7);
var days_between_without_weekends = days_between - (number_of_weekends*2);
return days_between_without_weekends;
},
type: 'dateTime'
});
Catalog Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var a=g_form.getValue('startdate');
var ga = new GlideAjax('dateTime');
ga.addParam('sysparm_name', 'dateTimeExcludingHolidays');
ga.addParam('sysparm_nam',a);
ga.getXML(CallBack);
function CallBack(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer>14||answer<=-1) //number of max days to be selected
{
g_form.clearValue('startdate');
g_form.addInfoMessage("selected date : "+a);
g_form.addInfoMessage("difference between dates : "+answer);
}}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 04:15 AM
by using your script- when i select Sunday, saturday dates - it is accepting, actually it should not...
i want Business Days Dates accept only , Sunday, saturday days does not take
it should not select Sunday, saturday 's dates.
if i select that give message like please select "Business Day"
var selday=objdate.getDay();
alert(selday);
if(selday==0||selday==6)
{
alert('select business day');
g_form.setValue('date','');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 03:31 AM
try now
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var seldate=g_form.getValue('date');
var objdate=new Date(seldate);
var selday=objdate.getDay();
var res = parseInt(selday);
alert(res);
if(res==0||res==6)
{
alert('select business day');
g_form.setValue('date','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 04:07 AM
still same kind of error message showing like "NaN"