getUTCHours() and getHours() return random numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:08 AM
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
Script included
Any idea why ? - San Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:12 AM
did you debug what came in logs and alert?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:16 AM
I debug it with logs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:58 AM
so what's your findings?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 05:56 AM
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