Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Convert incident created time to different time zones IST (India), SGT (Singapore) and JST (Japan)

vamsikrishnakat
Tera Contributor

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). 

1 ACCEPTED SOLUTION

Mohammed8
Mega Sage

Hi @vamsikrishnakat 

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);

 

Mohammed8_0-1763440426206.png

 

 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

 

View solution in original post

5 REPLIES 5

Hi Ankur,
Thank you for your Quick response.
Yes client needs, three new fields on the incident form
and based on created time, those three fields should be automatically updated with respective time zones(IST,SGT and JST)