Null pointer exception for date

sigmachiuta
Kilo Guru

I am trying to run a script include that will skip the weekend. I keep receiving an error on getDayOfWeek()

java.lang.NullPointerException

function checkDate(x) {

  var gdt = new GlideDateTime(x);

  var day = gdt.getDayOfWeek();

  if (day == 1) {

  return gdt < gs.daysAgo(3);

  } else {

  return gdt < gs.daysAgo(1);

  }

}

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

HI sigmachiuta,



I doubt on the parameter(x) value, that you are passing to the GlideDateTime(x) class.



var gdt = new GlideDateTime('invalid date time format');  


var day = gdt.getDayOfWeek();



The above code   will produce null pointer exception. So, try adding log statements and check once?



gs.log("x vlalue is"+x);


var gdt = new GlideDateTime(x);  


var day = gdt.getDayOfWeek();



Cheers


Srini


View solution in original post

1 REPLY 1

srinivasthelu
Tera Guru

HI sigmachiuta,



I doubt on the parameter(x) value, that you are passing to the GlideDateTime(x) class.



var gdt = new GlideDateTime('invalid date time format');  


var day = gdt.getDayOfWeek();



The above code   will produce null pointer exception. So, try adding log statements and check once?



gs.log("x vlalue is"+x);


var gdt = new GlideDateTime(x);  


var day = gdt.getDayOfWeek();



Cheers


Srini