- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 10:13 AM
I have a requirement that when a change request is submitted if the "requested by date" is within a certain "daytime deployment" schedule it must route for additional approvals and warn the user submitting the request. I've gotten the workflow / approval portion to work, but I'm having trouble with the user warning portion. I'm trying to create an on submit client script that calls a script include to check the requested by date against the schedule and passes the results back to the client script. For some reason the answer I'm getting back from the script include is always false no matter what date I select. Can anyone help me identify the problem?
Client Script:
function onSubmit() {
var ga = new GlideAjax('iSchedule');
ga.addParam('sysparm_name', 'GetInSchedule');
ga.addParam('sysparm_schedule', '3963d6bd4f168300fb43a3928110c754');
ga.addParam('sysparm_reqDate', g_form.getValue('requested_by_date'));
ga.getXMLWait();
var answer = ga.getAnswer();
alert(answer);
if (answer == 'true') {
var result = confirm('Your requested by date falls within the daytime deployment window and will require additional approvals. Do you wish to proceed?');
if (result == false) {
return false;
}
}
}
Script Include:
var iSchedule = Class.create();
iSchedule.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetInSchedule: function() {
var schedule = this.getParameter('sysparm_schedule');
var rbdt = this.getParameter('sysparm_reqDate');
var sched = new GlideSchedule(schedule);
var chkDT = new GlideDateTime(rbdt);
if (sched.isInSchedule(chkDT)) {
return 'true';
} else {
return 'false';
}
},
GetOutSchedule: function() {
var schedule = this.getParameter('sysparm_schedule');
var rbdt = this.getParameter('sysparm_reqDate');
var sched = new GlideSchedule(schedule);
var chkDT = new GlideDateTime(rbdt);
if (!sched.isInSchedule(chkDT)) {
return 'true';
} else {
return 'false';
}
},
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 10:43 AM
Chase, dates can be a pain in the rear. I suspect that user and server time zones are at fault here. I would suggest alerting the date in your client script before the Ajax call, then in your script include log the value of chkDT and compare. I suspect they are off by your timezone offset. You may need to do:
var chkDT = new GlideDateTime().setDisplayValue(rbdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 10:43 AM
Chase, dates can be a pain in the rear. I suspect that user and server time zones are at fault here. I would suggest alerting the date in your client script before the Ajax call, then in your script include log the value of chkDT and compare. I suspect they are off by your timezone offset. You may need to do:
var chkDT = new GlideDateTime().setDisplayValue(rbdt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 12:43 PM
Interesting. Since the schedule has a time zone defined I assumed the isInSchedule functionality would just account for the time zone the check date was in. In any event you have set me on the right path! Changing the line to
var chkDT = new GlideDateTime().setDisplayValue(rbdt);
resulted in the script include returning a null answer but using
var chkDT = new GlideDateTime();
chkDT.setDisplayValue(rbdt);
seems to have it working. Thanks for the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 01:00 PM
Interesting. Since the schedule has a time zone defined I assumed the isInSchedule functionality would just account for the time zone the check date was in.
It does factor the timezone, but since you are establishing date to use server side, it uses the server's timezone. You can use teh setTimeZone function to change it like the following:
var userTZ = gs.getUser().getTZ();
var schedule = new GlideSchedule(schedule);
schedule.setTimeZone(userTZ);