- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a requirement in ServiceNow based on created time of incident, that time will be converted into other time zones for Singapore and Japan and India. for that i have created 3 fields with different time zones. IST time SGT time and JST time. Now if i create an incident, that incident created based on IST time zone , because user from IST, now that time will be convert into IST time(u_ist_time), SGT time(u_sgt_time) and JST time(u_jst_time).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
You can follow this business rule (Before) for your particular use case.
(function executeRule(current, previous) {
function convertToTZDateTime(baseGdt, zone) {
var g = new GlideDateTime(baseGdt);
// Set display timezone
g.setTimeZone(zone);
var local = g.getDisplayValue(); // "yyyy-MM-dd HH:mm:ss"
var finalGDT = new GlideDateTime();
finalGDT.setDisplayValue(local);
return finalGDT;
}
var created = current.sys_created_on.getGlideObject();
current.u_ist = convertToTZDateTime(created, "Asia/Kolkata");
current.u_sgt = convertToTZDateTime(created, "Asia/Singapore");
current.u_jst = convertToTZDateTime(created, "Asia/Tokyo");
})(current, previous);
best practice is as @Palash_Sarkar has mentioned in his comment
Please mark it as helpful/solution accepted if you find this useful
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Instead of creating separate fields to store times in multiple time zones, it is best practice to convert the Incident’s existing Created time dynamically whenever it is needed. Since ServiceNow stores all date/time values in UTC, you can transform sys_created_on into IST (India), SGT (Singapore), or JST (Japan) using GlideDateTime with the appropriate time-zone codes. This approach avoids unnecessary custom fields and keeps the data model clean and efficient.
Business Rule Example: Dynamic Time-Zone Conversion
You can use this in a Before or After Business Rule to log or process the converted times without storing them in additional fields.
Type: Before or After Insert/Update
Table: Incident
(function executeRule(current, previous) {
// Original Created time in UTC
var createdDT = new GlideDateTime(current.sys_created_on);
// Convert to IST (India)
var ist = new GlideDateTime(createdDT);
ist.setTZ('Asia/Kolkata'); // IST
gs.info("Created Time in IST: " + ist.getDisplayValue());
// Convert to SGT (Singapore)
var sgt = new GlideDateTime(createdDT);
sgt.setTZ('Asia/Singapore'); // SGT
gs.info("Created Time in SGT: " + sgt.getDisplayValue());
// Convert to JST (Japan)
var jst = new GlideDateTime(createdDT);
jst.setTZ('Asia/Tokyo'); // JST
gs.info("Created Time in JST: " + jst.getDisplayValue());
})(current, previous);
Notes
-
getDisplayValue()will return the converted time as a string in the target time zone. -
This method does not require custom fields, and you can use it whenever needed—e.g., in scripts, notifications, or reports.
-
You can also adapt it for Client Scripts or Script Includes if you want to show these times dynamically in the UI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
You can follow this business rule (Before) for your particular use case.
(function executeRule(current, previous) {
function convertToTZDateTime(baseGdt, zone) {
var g = new GlideDateTime(baseGdt);
// Set display timezone
g.setTimeZone(zone);
var local = g.getDisplayValue(); // "yyyy-MM-dd HH:mm:ss"
var finalGDT = new GlideDateTime();
finalGDT.setDisplayValue(local);
return finalGDT;
}
var created = current.sys_created_on.getGlideObject();
current.u_ist = convertToTZDateTime(created, "Asia/Kolkata");
current.u_sgt = convertToTZDateTime(created, "Asia/Singapore");
current.u_jst = convertToTZDateTime(created, "Asia/Tokyo");
})(current, previous);
best practice is as @Palash_Sarkar has mentioned in his comment
Please mark it as helpful/solution accepted if you find this useful
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you Mohammed
script works
Awesome 🖖
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what's the requirement to create custom fields just to store the converted time?
That will help us to help you better.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
