Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Returning fault result in workflow if conditional activity

Nilesh Pol1
Giga Guru

Hi all,

I working on schedule for CM, where I want return yes/no based on schedule entry.

let say if we put the planned start/end date that fouls under the schedule then result should be in yes or no.

I working with following script which returning a result with 'fault'.

is there any issue in the script?

please support.

 

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', 'Monthly change freeze 2024');

    var schedRec1 = new GlideRecord('cmn_schedule_span');
    schedRec1.addQuery('name', 'Monthly change freeze 2024');
    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';
    }
}
0 REPLIES 0