Date calculate based on selected time zone

gillerlaraj
Tera Contributor

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

Ankur Bawiskar
Tera Patron
Tera Patron

@gillerlaraj 

what's your business requirement?

the 1st date/time has to be converted into which timezone and stored in 2nd?

But why

If users submitting are in IST then they can simply select IST time there?

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

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

hi @Ankur Bawiskar ,

 

Thanks for Reply....

 

My requirement is based on one Hour before schedule start i need to create a sctask, but instance is following IST timezone if user choose time zone as CST/PST etc., so in that case also it's to following IST only not user specified timezone in the form.

 

so that's why i am converting date& time based on timezone and based on the i need to create sctask.

 

 

@gillerlaraj 

if you are using flow then when flow runs it takes GMT time.

You can perform the calculation there and based on that 1 hr before the date selected you can create task

I created blog to convert date/time to different timezone, use that and enhance it as per your requirement

this converts UTC to IST for example

// for CST you can use CST in 1st parameter

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)
gs.info(gdtConvertedDateTime);

AnkurBawiskar_0-1744385821730.png

 

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

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

Hi @Ankur Bawiskar ,

 

i don't have  option to convert in flow ,

gillerlaraj_0-1744386754104.png

you saying , can i convert custom action to convert ?

 

Regards,

Rajesh