- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 05:27 AM
Hi,
I have a scoped workflow that needs to wait until specified "end_time" (date/Time) along with "timezone" on catalog item form is completed.
I only know I need to use Timer activity for this can you please help me with the scripting?
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 04:27 PM
Hi Divya,
Adding a timezone might give a better user experience but it can/ should be avoided to avoid any developmental overheads.
You may keep a single field (date time) and request the user to select the appropriate time considering his own timezone.
Also, the value of the variable on the RITM variable editor form would be confusing as well. For example, value during ticket creation by an IST user at 16:30 + CET timezone, would display 13:00 +CET for an european users. (reason is servicenow stores the datetime backend value converted to UTC based on the the ticket creators timezone while displays based on the current logged in users timezone)
*********************************************************************************
However, in case you decide to go with the custom solution, you can follow the below approach using moment.js library
gs.include("moment.js");
gs.include("moment-timezone-with-data-1970-2030.js");
var ritmGr = new GlideRecord("sc_req_item");
ritmGr.get("ea6d8dd61b799c102f967669cd4bcb54");//sys_id of a RITM record
var tZSetOnVar='';
var shouldBeTZ = ritmGr.variables.u_timezone.toString();
//--calculate the timezone of the requestor
var usrGr = new GlideRecord('sys_user');
usrGr.addQuery('user_name',ritmGr.sys_created_by);
usrGr.query();
if(usrGr.next())
{
tZSetOnVar= usrGr.time_zone.toString();
}
if(typeof tZSetOnVar=='undefined' || tZSetOnVar=='')
{tZSetOnVar = gs.getProperty('glide.sys.default.tz');
}
var requestedDateTime = new GlideDateTime(ritmGr.variables.u_schedule_downtime_start);
var currentDateTime = new GlideDateTime();
var tZSetOnVarOffSet = moment.tz(moment.utc(), tZSetOnVar).utcOffset();
var shouldBeTZOffSet = moment.tz(moment.utc(), shouldBeTZ ).utcOffset();
var totalSpan = requestedDateTime.getNumericValue() - currentDateTime.getNumericValue() + tZSetOnVarOffSet*60*1000 - shouldBeTZOffSet*60*1000 ;// as the requestor might be in a different timezone than the requested for user, we need to apply the timezone offset between requestor's timezone and requested for's timezone
gs.info("Total timespan in millis: "+totalSpan);// this will give the actual time difference from current time to the actual downtime requested
Output:
Helpful link -
https://stackoverflow.com/questions/32878197/updating-time-offset-with-moment-utcoffset
moment.js library can be imported from -
Regards,
Anirban
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 05:34 AM
Hi Divya,
you can use timer activity
sharing links for help
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 05:42 AM
Hi,
You need to calculate the difference from current date time to end time and set it in timer. Use subtract function for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 06:06 AM
Thanks for your reply. For getting the time difference, I need both current date time & end_time in the same time zones.
So can you help me with getting the current date time in any specified time zone?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 06:23 AM
Hi Divya,
sharing few links for help
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader