Convert Time to different time zones based on the user's selection.

uday_kumar_b
Tera Contributor

Hi all,

I'm looking for some assistance in converting time from MST to other 5 different time zones on CR form field.
The 'actual work start' field will auto populate once the CR is moved to implement state and the time it's auto populating is MST irrespective of the selection in 'Time Zone' field. The time it should auto populate and convert into the time zone based on the time zone selected in 'Time Zone' field. I'm able to convert to other time zones accurately but the time in 'actual work start' field it's displaying is UTC time(may be I'm missing something here).

 

Here is the BR I've written when CR state is 'implement' run 'after' update/insert:

 

var gdt = new GlideDateTime();

    if (current.u_time_zones == "US/Arizona") {
        gdt.setTimeZone('US/Arizona');
        current.work_start = gdt.getDisplayValue();
    } else if (current.u_time_zones == 'US/Central') {
        gdt.setTimeZone('US/Central');
        current.work_start = gdt.getDisplayValue();
    } else if (current.u_time_zones == 'US/Eastern') {
        gdt.setTimeZone('US/Eastern');
        current.work_start = gdt.getDisplayValue();
    } else if (current.u_time_zones == 'US/Hawaii') {
        gdt.setTimeZone('US/Hawaii');
        current.work_start = gdt.getDisplayValue();
    } else if (current.u_time_zones == 'US/Mountain') {
        gdt.setTimeZone('US/Mountain');
        current.work_start = gdt.getDisplayValue();
    } else if (current.u_time_zones == 'US/Pacific') {
        gdt.setTimeZone('US/Pacific');
        current.work_start = gdt.getDisplayValue();
    }
 
 
I checked using background script and am able covert times correctly:

var gdt = new GlideDateTime(); //- utc

gs.print('utc time: '+gdt);

gdt.setTimeZone('US/Arizona');
gs.info('US/Arizona: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Central');
gs.info('US/Central: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Eastern');
gs.info('US/Eastern: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Hawaii');
gs.info('US/Hawaii: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Mountain');
gs.info('US/Mountain: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Pacific');
gs.info('US/Pacific: '+gdt.getDisplayValue());

 

Output:

uday_kumar_b_0-1711552102169.png

 

But while running the business rule with the same logic and setting it to 'Actual work start', it's displaying the UTC time instead of the converted time zone. 
Any help is much appreciated, thanks 




5 REPLIES 5

One use case that I am trying to solve is a using a record producer form where a user can select a location and request a visit time.  The form will expect the time to be in the location's time zone and not the user's time zone.  However, when submitting a form through the record producer on the service portal or CSM, the time is submitted as the user's time zone.  Hence the time needs to be converted from the user's time zone to the location's time zone.  I am having difficulty achieving a method to do this, considering the user's permissions as customers and the form running in the Customer Service application.

 

Anyone have any suggestions?