- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 02:10 AM
Hello All,
I have created scheduledfor freeze period.I want to check my start date and end date are passing through schedule or not.Can some one help me to get a solution for this?
answer = ifScript();
function ifScript() {
var scheduled_start_date = current.start_date;
var scheduled_end_date = current.end_date;
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name','Freeze Period');
var sched = new GlideSchedule(schedRec.sys_id);
var gdt_start = new GlideDateTime(scheduled_start_date);
var gdt_end= new GlideDateTime(scheduled_end_date);
if ((sched.isInSchedule(gdt_start))||(sched.isInSchedule(gdt_end))) {
return 'yes';
}
else
{
return 'no';
}
}
I have four scenario this needs return yes.
1) Planned start date is before schedule or End Date in within schedule .
2)Planned start date is within schedule or end date is in after schedule .
3)Planned start date and end date are within schedule .
4)Planned start date is before schedule and planned end date is after schedule and thist pass through the schedule or not
My 4th scenario is not working as per the above script.
Can some one please help me to fix it?
Thanks
saranya
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017 02:21 AM
Hello Chuck,
Thanks for the information.
I got the solution
answer = ifScript();
function ifScript() {
var scheduled_start_date = current.start_date;
var scheduled_end_date = current.end_date;
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name','Freeze Period');
var schedRec1 = new GlideRecord('cmn_schedule_span');
schedRec1.addQuery('name','Freeze Period');
schedRec1.query();
var start;
var end;
if(schedRec1.next())
{
start=schedRec1.start_date_time.getDisplayValue();
end=schedRec1.end_date_time.getDisplayValue();
}
var sched = new GlideSchedule(schedRec.sys_id);
var gdt_start = new GlideDateTime(scheduled_start_date);
var gdt_end= new GlideDateTime(scheduled_end_date);
if ((sched.isInSchedule(gdt_start))||(sched.isInSchedule(gdt_end)) || (scheduled_start_date <= start && scheduled_end_date >= end)) {
return 'yes';
}
else
{
return 'no';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 05:48 AM
Hi Saranya,
isInSchedule() only checks if the data is within the one of the schedule's periods. I think your fault is in assuming there is a "before" and "after" to the schedule. If the schedule only has one period, sure, that might work, but the point of schedules is to make repeating easy. Example: Monday-Friday 0800-1700. That's every day, every week. What does "before" mean? Is 3:00AM before 0800 or after 1700? With a schedule a time is either in or out of that schedule, so your logic won't work here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017 02:21 AM
Hello Chuck,
Thanks for the information.
I got the solution
answer = ifScript();
function ifScript() {
var scheduled_start_date = current.start_date;
var scheduled_end_date = current.end_date;
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name','Freeze Period');
var schedRec1 = new GlideRecord('cmn_schedule_span');
schedRec1.addQuery('name','Freeze Period');
schedRec1.query();
var start;
var end;
if(schedRec1.next())
{
start=schedRec1.start_date_time.getDisplayValue();
end=schedRec1.end_date_time.getDisplayValue();
}
var sched = new GlideSchedule(schedRec.sys_id);
var gdt_start = new GlideDateTime(scheduled_start_date);
var gdt_end= new GlideDateTime(scheduled_end_date);
if ((sched.isInSchedule(gdt_start))||(sched.isInSchedule(gdt_end)) || (scheduled_start_date <= start && scheduled_end_date >= end)) {
return 'yes';
}
else
{
return 'no';
}
}