Workflow If Statement to check if ticket created after hours

EricG
Kilo Sage

I'm getting an error that the system can not convert my variable (var endTime = new GlideTime("17:30:00").   Getting "Cannot convert 17:30:00 to java.lang.Long".

 

Request:

If task is created during After Hours (after 5pm but before 7:30am) then assign to after hours group.

 

Workflow Activity If State:

answer = ifScript();

function ifScript() {
    var ticketTime = current.created_on;
    var inBhour = '';
    var gdt = new GlideDateTime(ticketTime);
    gt = gdt.getTime();

    var endTime = new GlideTime("17:30:00");
    var startTime = new GlideTime("08:30:00");
    if (gt < endTime && gt > startTime) {
        inBhour = true;
    }

    if (inBhour == true) {
        return 'yes';
    }
    return 'no';
}

 

Any suggestions on what i should do?

1 ACCEPTED SOLUTION

OK, i'm coffee deprived.  Once i really looked, it's working.  However the suggestions for Time Zones didn't work.  The if activity didn't like it.

answer = ifScript();

function ifScript() {
    var ticketTime = current.sys_created_on;
	
    var gdt = new GlideDateTime(ticketTime);
    gt = gdt.getTime();

    var endTime = new GlideTime();
		
    var startTime = new GlideTime();

    startTime.setValue('12:30:00');//time zone need to add 5 for time zone was 07

    endTime.setValue('22:00:00');
	
	//gs.info('The gt is '+gt+" and end/start "+endTime+"/"+startTime); 
    if (gt < endTime && gt > startTime) {
		
        return 'yes';

    } else {
        return 'no';

    }
}

 

View solution in original post

3 REPLIES 3

Abbas_5
Tera Sage
Tera Sage

Hello @EricG ,

Please refer to the below link:
https://www.servicenow.com/community/itsm-forum/check-the-created-time-falling-in-between-business-h...


If it is helpful, mark it as a thumbs-up and accept the correction solution.

Thanks & Regards,
Abbas

Yes - saw that one and tried to use.

 

My Ticket time comes as 2023-10-10 13:00:00  but start and end times have 1970-01-01

at the start.  So not working.

OK, i'm coffee deprived.  Once i really looked, it's working.  However the suggestions for Time Zones didn't work.  The if activity didn't like it.

answer = ifScript();

function ifScript() {
    var ticketTime = current.sys_created_on;
	
    var gdt = new GlideDateTime(ticketTime);
    gt = gdt.getTime();

    var endTime = new GlideTime();
		
    var startTime = new GlideTime();

    startTime.setValue('12:30:00');//time zone need to add 5 for time zone was 07

    endTime.setValue('22:00:00');
	
	//gs.info('The gt is '+gt+" and end/start "+endTime+"/"+startTime); 
    if (gt < endTime && gt > startTime) {
		
        return 'yes';

    } else {
        return 'no';

    }
}