How can I check that the Current Time is after a Specific Time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2018 10:58 PM
I need to set a flag field based on the time that an Incident is raised.
I need to compare the current time with specific time, depending on the client. For example, if the Created time is after 18:00 set the flag to TRUE. What would be the syntax for the checking the time?
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2018 02:35 AM
Hi,
You can use below script to get current time.
var gdt = new GlideDateTime(); // current time in GMT
var userDateTimeZone = gdt.getDisplayValue(); // in local time
var userTime = userDateTimeZone.split(' ')[1]; // parsed time field
gs.print(userTime); // return in HH:MM:SS format
Since userTime is in the format HH:MM:SS, we can compare it with specific time as per normal string comparison.
if (userTime > Specific time) {
// Incident condition to set flag true
}
Provided both are in HH:MM:SS format (userTime is already in this format).
Hope this helps.
Thanks,
Himanshu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2018 02:54 AM
HI,
This will solve your issue:
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
Thanks,
Ashutosh