How to find the recurring schedule entry record that conflicts with change request schedule?

abhi710
Tera Contributor

Hi,

There is a requirement to find the all recurring and non- recurring schedule entry record that conflicts with change request schedule.

I have found the logic for non-recurring schedule:

After BR on conflict table: 

 var sysId = current.change;
    var gr = new GlideRecord("change_request");
    gr.addQuery("sys_id", current.change);
    gr.query();
    if (gr.next()) {
        var schedule = current.schedule.toString();
        var startDate = gr.start_date;
        var endDate = gr.end_date;
        var scheduleEntry = [];
        var spanGr = new GlideRecord("cmn_schedule_span");
        spanGr.addQuery('schedule', schedule);
        spanGr.addQuery('schedule.sys_class_name', 'cmn_schedule_blackout');
        spanGr.addQuery('u_blackout_end_time', '>=', startDate);
        spanGr.addQuery('u_blackout_start_time', '<=', endDate);
        spanGr.query();
        while (spanGr.next()) {

            scheduleEntry.push(spanGr.getValue('sys_id')).toString();
        }

        var scheduleIds = scheduleEntry.join(", ");   
current.u_schedule_entry = scheduleIds;
    }

gs.info("Number of conflicts: " + spanGr.getRowCount());

gs.info("Conflicting Schedule Entry Ids: " + scheduleIds);

This code only returns the non- recurring record couldn't apply for recurring schedule entry record. 

Example: See attached SS there are repeat schedule - there we can see one schedule entry which has 15/8 has start and end date time; it repeats every friday till 11/09. So, if change request is scheduled at 22/08 (friday); it doesn't show the schedule entry name but the conflict is detected due that schedule entry schedule with change request's schedule.

Background Script:

var scheduleSysId = 'abc';

var startTime = new GlideDateTime('2025-08-22 10:03:35');

var endtime = new GlideDateTime('2025-08-22 11:50:40');

 

var scheduleEntryNames = [];

var gr = new GlideRecord('cmn_schedule_span');

gr.addQuery('schedule', scheduleSysId);

gr.addQuery('u_blackout_end_time', '>=', startTime);

gr.addQuery('u_blackout_start_time', '<=', endtime);

gr.query();

while (gr.next()) {

    scheduleEntryNames.push(gr.getValue('name'));

   

}

gs.print("Number of conflicts: " + gr.getRowCount());

 

gs.print("Conflicting Schedule Entry Names: " + scheduleEntryNames.join(", "));


How to apply repeat logics(recurring) of schedule entry in code and get the exact schedule entry record?

Is there any OOB API to get the recurring schedule and get the exact schedule entry record? Need to modify code with recurring logic.

 

 

 




 

 

 



0 REPLIES 0