Need to convert Date field to populate only in EST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 04:27 AM
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'
});
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 04:34 AM
It always shows as per the timezone you have set for yourself in your preference. But in the backend it is stored correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 04:37 AM
Hi,
what's your requirement?
The date/time value shown on form is based on user's timezone or the settings from gear icon
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 05:22 AM
Hi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 05:38 AM
Hi,
you can convert it like this to EST
update as this
var getDateInEST = Class.create();
getDateInEST.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getConvertedDate: function() {
var mydate = new GlideDateTime(this.getParameter('sysparm_date').toString());
var sourceTimeZone = 'GMT';
var targetTimeZone = 'EST';
var finalValue = global.rmConvertTimeZone(dateTime, sourceTimeZone, targetTimeZone);
return finalValue;
},
type: 'getDateInEST'
});
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.getXMLAnswer(function(answer){
g_form.setValue('account_number_or_feed_id', answer);
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader