Need to convert Date field to populate only in EST

Mounica2
Tera Contributor

Hi

I need to make a date/time field to populate only in EST and not change according to the user time zone who selects them. I have written a client script and script include to achieve this but I am getting by default, 2022-06-01 and time 7.30 hours ahead of the time selected. Can someone please guide mw with the correct query,
Below is the query that I used,

Catalog Client Script : 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

 
var ga = new GlideAjax('getDateInEST');
ga.addParam('sysparm_name', 'getConvertedDate');
ga.addParam('sysparm_date', g_form.getValue('statement_date')); //Getting the Date field here
ga.getXML(getDataResponse);

function getDataResponse(response) {
var favorites = response.responseXML.getElementsByTagName("favorite");
g_form.setValue('account_number_or_feed_id', favorites[0].getAttribute('statement_date'));
}

}

 

Script Include :

var getDateInEST = Class.create();
getDateInEST.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getConvertedDate: function() {
var mydate = new GlideDateTime(this.getParameter('sysparm_date').toString());

//sets to EST
var tz = Packages.java.util.TimeZone.getTimeZone('US/Eastern');
var gdt = new GlideDateTime();
gdt.setTZ(tz);
var abc = gdt.getDisplayValue();
var favs = this.newItem('favorite');

favs.setAttribute('statement_date',abc);
},
type: 'getDateInEST'
});

 

7 REPLIES 7

Hi Ankur,

This is returning 'Null' as the value

Hi,

so what debugging did you perform?

is gs.info() returning valid values in script include?

Regards
Ankur

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

Hi @Ankur Bawiskar ,

in script include for source time zone it is only used GMT, but I need to handle all time zones, can you please help me on this.

 

Thanks & regards,

Hemanth,