show calendar date/time fields in EST

Shivam Saxena1
Mega Expert

Hello,

 

We have 2 fields in a form.

1. Expected Start Date/Time

2. Expected End Date/Time

 

The above 2 fields show the system date/time.

 

I want 2 more fields below below the above mentioned fields with name :

1. Expected Start Date/Time (EST)

2. Expected End Date/Time (EST)

 

Requirement :

Expected Start Date/Time (EST) will be copied from Expected Start Date/Time once the user fill this field and show EST time.

Expected End Date/Time (EST) will be copied from Expected End Date/Time once the user fill this field and show EST time.

 

Can someone please help in how to achieve this functionality?

 

 

NOTE : The fields are in scoped application.

1 ACCEPTED SOLUTION

Okay.

Hi create a SI in global scope and then call that Si from your client script. Then you can use the following code to convert your date/time to EST format.

 

Script Include

getConvertedDate: function() {
       var mydate = new GlideDateTime(this.getParameter('sysparm_date').toString());
       var gdt1 = new GlideDateTime();
       //sets to EST
       var tz = Packages.java.util.TimeZone.getTimeZone("EST");
       gdt1.setTZ(tz);
       gdt1.setValue(mydate); 
       return gdt1.getDisplayValue(); //returns the date/time in EST timezone as a string.
},


Mark the comment as a correct answer and also helpful if this helps to solve the problem.

View solution in original post

30 REPLIES 30

Hi,

The syntax is wrong. template.print() takes only 1 arguent. So there shoudl not be comma.

Here is how to show

template.print("Expected start : "+current.your_field.getDisplayValue());

Mark the comment as helpful if it helps.

 

Hi Asif,

 

It is not coming correctly.

 

The issue is while sending notification, the time is getting converted into GMT again.

 

In form, user fill 'Expected Start Date/Time' and 'Expected End Date/Time' and our script include and client script converting that Date/Time value in EST and populate the same in 'Expected Start Date/Time (EST)' and 'Expected End Date/Time (EST)' fields.

 

I want 'Expected Start Date/Time (EST)' and 'Expected End Date/Time (EST)' fields to be printed in notification in EST.

 

But I am getting wrong values.

 

Change Form :

 

find_real_file.png

 

Email getting :

 

find_real_file.png

 

Mail Script : print_time_in_EST

 

find_real_file.png

 

Notification :

 

find_real_file.png

 

Thanks.

Hi,

can you try getValue() instead of getDisplayValue() and check it once.

HI Asif,

 

I have checked. It is not working.

It is not printing anything now.

 

find_real_file.png

 

Thanks.

Okay.

In that case, i suggest you call the same SI code in the mail script and check it once.

var mydate = new GlideDateTime(current.your_field);
var gdt1 = new GlideDateTime();
//sets to EST
var tz = Packages.java.util.TimeZone.getTimeZone("EST");
gdt1.setTZ(tz);
gdt1.setValue(mydate); 
template.print("Expected Start Date/Time: "+gdt1.getDisplayValue());