- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 05:15 PM
Hi Guys,
I am trying to alert users on a Service Catalog item when they select a public holiday or a weekend. The problem is it is very erratic, sometimes it works but sometimes it doesn't.
Here is the code I have on the instance and the I tried with both getXML and getXMLWait to no avail:
Script Include:
var SNCVisitorNetValidation = Class.create();
SNCVisitorNetValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkInSchedule: function(){
var scheduled_date = this.getParameter('sched_date');
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name','8-6 weekdays excluding holidays');
var sched = new GlideSchedule(schedRec.sys_id);
var gdt = new GlideDateTime(scheduled_date);
if (sched.isInSchedule(gdt)) {
gs.log('true ' + gdt);
return true;
}
else
{
gs.log('false ' + gdt);
return false;
}
},
type: 'SNCVisitorNetValidation'
});
Client Script:
var ga = new GlideAjax('SNCVisitorNetValidation');
ga.addParam('sysparm_name','checkInSchedule');
ga.addParam('sched_date', start_date);
//ga.getXML(checkInSchedule);
ga.getXMLWait();
answer = ga.getAnswer();
if(answer == 'true')
{
alert ('working day');
}
else if (answer == false')
{
alert ('holiday');
}
Could you please check and let me know if you can spot anything?
Mussie
P.S. BTW, if I test this using the Background script it works
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2016 05:48 PM
That brings up a good question... where did start_date come from? Should that be:
ga.addParam('sysparm_sched_date', g_form.getValue('start_date'));
Instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 04:15 PM
please find me a solution for the below query.
*** Script: userTimezonesun.util.calendar.ZoneInfo[id="Europe/Dublin",offset=0,dstSavings=3600000,useDaylight=true,transitions=227,lastRule=java.util.SimpleTimeZone[id=Europe/Dublin,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
var ga = gs.getSession().getTimeZone();
gs.info('userTimezone'+ga);
var cor = new GlideRecord('x_novrp_it_it_change');
cor.addQuery('sys_id', '96fa52c98786461049aa0d030cbb359c');
cor.query();
if (cor.next()) {
var startdateofchgci = cor.start_date;
var enddataeofchgci = cor.end_date;
gs.info('startdateofchgci'+startdateofchgci);
gs.info('enddataeofchgci'+enddataeofchgci);
}
var scheduleEntryGRsoft = new GlideRecord('cmn_schedule_span');
scheduleEntryGRsoft.addQuery('schedule', 'b257e7a11b398e5884e2caa16b4bcb62');
scheduleEntryGRsoft.query();
if (scheduleEntryGRsoft.next()) {
var schedulesysid = scheduleEntryGRsoft.schedule;
var recurrencerule = scheduleEntryGRsoft.schedule;
var schedule = new GlideSchedule(recurrencerule);
schedule.setTimeZone('Europe/Dublin');
var gdt_start = new GlideDateTime(startdateofchgci);
var gdt_end = new GlideDateTime(enddataeofchgci);
var dur = schedule.duration(gdt_start, gdt_end);
var schedule_time = dur.getNumericValue() / 1000;
if ((schedule.isInSchedule(gdt_start)) || (schedule.isInSchedule(gdt_end)) || (schedule_time > 0)) {
gs.info('FOUND IN SCHEDULES:');
}else{
gs.info('NOT FOUND IN SCHEDULES:');
}
}