- 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 06:26 AM
Hi Divya,
This is for current time:
var tz = "<Timezone value> i.e.Canada/Eastern";
var gDT = new GlideDateTime();
gDT.setTZ(tz);
var abc = gDT.getDisplayValue();
For a field time use:
var tz = "<Timezone value> i.e.Canada/Eastern";
var gDT = new GlideDateTime(current.<field_name>);
gDT.setTZ(tz);
var abc = gDT.getDisplayValue();
Check this link for reference: https://community.servicenow.com/community?id=community_question&sys_id=4714cfe5dbd8dbc01dcaf3231f96...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 06:33 AM
The mentioned methods are not working for scoped application
Function setTZ is not allowed in scope.
Use of Packages calls is not permitted in scoped applications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 10:56 AM
please refer below links:
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:43 AM

- 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