Date calculate based on selected time zone

Not applicable

Hi Everyone,

 

The instance is following IST time zone and all users profiles are also in IST time zone,

 

gillerlaraj_0-1744379580611.png

 

now based on schedule visit date time and time zone i need to calculate the date and time and populate in the field.

but it's not working expected.

 

script include:

----------------------------------------

timeCalculation:function(){

        var date=this.getParameter('sysparm_date');
        gs.log("selected Date is:"+date);
        var tzone=this.getParameter('sysparm_tzone');
        var fdate=new GlideDateTime(date);
        fdate.setTimeZone(tzone);
        return fdate.getDisplayValue();
    },
 
Glide ajax:
-------------------------
 var schedule=g_form.getValue('scheduled_visit_date_time');
   var tzone=g_form.getValue('timezone');
   alert(schedule);
   alert(tzone);

   var ajax=new GlideAjax("Date_time_calculation_based_on_Timezone");
   ajax.addParam('sysparm_name','timeCalculation');
   ajax.addParam('sysparm_date',schedule);
   ajax.addParam('sysparm_tzone',tzone);
   ajax.getXMLAnswer(response);

   function response(result){
    alert("date as per time zone"+result);
    g_form.setValue('scheduled_date_time_based_on_timezone',result);
   }

------------

any suggestions pls.

 

 

Regards,

Rajesh

 

any suggestions pls.

 

 

7 REPLIES 7

@Community Alums 

you can use a flow variable and store the calculated date/time in that and then use that in your flow

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Not applicable

Hi @Ankur Bawiskar ,

 

it showing like this, now my Question is it will start at duration time or wake up time mentioned in the action

Nadee33
Tera Contributor

If you are using a Flow; I believe Transform Function will help you here. 

To change the time from UTC to your local time, Please refer to the "Localize a field value's time zone"

topic https://www.servicenow.com/docs/bundle/yokohama-build-workflows/page/administer/flow-designer/refere...

 

I hope this will help. 

 

Thank you,