
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 10:53 PM
Hello,
I want to convert DateTime value which would be based on requester's TimeZone.
If my TimeZone is IST and requester's TimeZone is 'America/New York' then I should see 'America/New York' time in RITM variable.
I have written a code like below:
OnLoad Client Script on RITM table :
function onLoad() {
var dateTime = g_form.getValue('variables.access_start').toString();
var getSysID = g_form.getUniqueValue();
var gaGetTimeZone = new GlideAjax('ShowDateTimeOfRequester');
gaGetTimeZone.addParam('sysparm_name','updateDateTime');
gaGetTimeZone.addParam('ritm_sys_id',getSysID);
gaGetTimeZone.addParam('selected_date',dateTime);
gaGetTimeZone.getXML(setDateTimeOfRequester);
function setDateTimeOfRequester(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('Answer return ' +answer);
g_form.setValue('access_start',answer);
}
}
Script Include :
var ShowDateTimeOfRequester = Class.create();
ShowDateTimeOfRequester.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateDateTime: function() {
var requester, time ;
var selectedDate = this.getParameter('selected_date');
var ritmSysID = this.getParameter('ritm_sys_id');
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('sys_id',ritmSysID);
grReqItem.query();
if(grReqItem.next()) {
requester = grReqItem.request.requested_for;
}
var user = new GlideRecord('sys_user');
user.query('sys_id',requester);
user.query();
if(user.next()) {
time = new GlideDateTime(selectedDate);
gs.addInfoMessage('First Time ' +time);
var tz = Packages.java.util.TimeZone.getTimeZone(user.time_zone);
time.setTZ(tz);
gs.addInfoMessage('Requester Time is ' +time);
gs.addInfoMessage('Requester Display Time is ' +time.getDisplayValue());
}
return time;
},
type: 'ShowDateTimeOfRequester'
});
But its not working 😞
Please provide any solution.
Awaiting for your response.
--
Thanks,
Pooja
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2018 12:14 AM
https://community.servicenow.com/community?id=community_question&sys_id=b28a4fe9db5cdbc01dcaf3231f96192b
Thanks
Please mark correct/helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 11:15 PM
I'm pretty sure it automatically does this out of box? I just tested in my developer instance. If you impersonate a user with a different time zone it automatically converts the date/time fields.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2018 12:01 AM
Yes Correct Chris.
But I don't want that to be converted.
My scenario is, we have to convert the TimeZone of logged-in user with Requester's TimeZone.
Suppose, logged-in User is 'Pooja' and TimeZone is 'IST'.
Requester is 'Sonali' and Sonali's TimeZone is 'America/New York', she has raised an req REQ00001 - RITM000012
DateTime of RITM000012 - 2018/04/05 00:30:00
So when Pooja opens RITM000012, then DateTime (Start Date) should be visible as 2018/04/05 00:30:00 (as per Sonali's TimeZone). That means everyone should be see Sonali's DateTime.
But currently Pooja can see DateTime as 2018/04/05 10:00:00 (as per Pooja's TZ)
That I have to convert my timezone with her tz.
Hope this clarifies.
Please let me know if any changes required in above code.
--

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2018 12:14 AM
https://community.servicenow.com/community?id=community_question&sys_id=b28a4fe9db5cdbc01dcaf3231f96192b
Thanks
Please mark correct/helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2018 01:14 AM
Thank you so much for your response.
Its working now.