Time and days of the week

Jamsta1912
Tera Guru

Hi all,

I'm trying to produce an onChange client script to determine whether the date entered in the 'start_date' field on a Change_Request is before or after NEXT Thursday (relative to NOW).

I've been looking at the guidance here: http://wiki.servicenow.com/index.php?title=GlideDateTime#GlideDateTime.28.29 but I'm struggling to see how I can create a GlideDateTime object and set it to the newValue of the 'start_date' field. But I may be heading in the wrong direction with this... Any advice appreciated.

Regards
Jamsta.

1 ACCEPTED SOLUTION

Igor1
Kilo Expert

For those not looking at current date and instead looking at a date field, I learned that you can use the getDayOfWeek Glide function to check against the current record (so you can use it in a business rule, or, in our case, a workflow). My script below checks to see if a start or end date/time for a change record is between Friday and Sunday, returning True (and sending the change for added review) if that is the case:

 

	answer = isWeekend();

	function isWeekend() {
	   var impstart = current.start_date.getGlideObject().getDayOfWeek();
	   var impend = current.end_date.getGlideObject().getDayOfWeek();
	   if (impstart >= 5 || impend >= 5) {
         return 'yes';
        }
       return 'no';
   }

View solution in original post

11 REPLIES 11

That's great to hear Jamie! Glad my troubles could assist someone else!


Igor1
Kilo Expert

For those not looking at current date and instead looking at a date field, I learned that you can use the getDayOfWeek Glide function to check against the current record (so you can use it in a business rule, or, in our case, a workflow). My script below checks to see if a start or end date/time for a change record is between Friday and Sunday, returning True (and sending the change for added review) if that is the case:

 

	answer = isWeekend();

	function isWeekend() {
	   var impstart = current.start_date.getGlideObject().getDayOfWeek();
	   var impend = current.end_date.getGlideObject().getDayOfWeek();
	   if (impstart >= 5 || impend >= 5) {
         return 'yes';
        }
       return 'no';
   }