Script Include : var WeekDay = Class.create(); WeekDay.prototype = Object.extendsObject(AbstractAjaxProcessor, { WorkDay: function() { var selected_date = this.getParameter("sysparm_date"); var d = new GlideDateTime(selected_date); var dayCount = d.getDayOfWeekLocalTime(); // gs.info("date count - " + dayCount); if(dayCount == 5 || dayCount == 6){ // 5 - sat & 6 - sun return true; } else { return false; } }, type: 'WeekDay' }); onChange Client Script : function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } var day = g_form.getValue('v_start_date'); var ga = new GlideAjax("WeekDay"); ga.addParam("sysparm_name", "WorkDay"); ga.addParam("sysparm_date", day); ga.getXML(Day); function Day(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); if (answer == 'true') { alert('Please select Week Days from Monday-Friday'); g_form.clearValue('v_start_date', true); } } }
Select Weekdays in the date field/Variable Servicenow
Working Code Asked question March 13, 2024