The CreatorCon Call for Content is officially open! Get started here.

getUTCHours() and getHours() return random numbers

dpradocacf
Tera Contributor

Hello,

I have a requirement in the Change Form to show a message when the user chooses a date on the weekend or between 6pm and 8am.

For this I have created a Client Script and a Script included.

Using the log I check the answer from getUTCHours() and getHours().

It works but when the user change the date a second time, it just give me back random numbers.

 

Client Script

clientscript.PNG

Script included

scriptinclude.PNG

 

Any idea why ? - San Diego

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@dpradocacf 

did you debug what came in logs and alert?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I debug it with logs

 

@dpradocacf 

so what's your findings?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vallabh Baradk2
Giga Guru

Hi @dpradocacf ,

 

try getting hours using below code

 

var gdttime = new GlideDateTime(new selected date);

  var time = gdttime.getTime();

  var timeCreated = time.getByFormat('HH:mm:ss');

var Timesplit = timeCreated.split(":");

var strTime = Timesplit[0];

 

Please mark it correct or  helpful if it works for you.

 

Thanks and Regards,

vallabh