Getting time based on user time zone in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 03:29 AM
Hi,
We are looking for a way to get a certain date and time in specific time zone using a script. While there are few methods available in the global application, we can't find any in a scoped application.
For example, the setTimeZone function is not available in scoped application:
var mytime = new GlideDateTime();
mytime.setTimeZone(user.time_zone);
Is there any parallel option in scoped application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:23 AM
Hi,
There is no parallel option in scoped application but you can create a script include in global scope and try below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:28 AM
Thank you, this is the only solution i found also. It does require to handle some caller restricted access records when you use the script from different scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:29 AM
Hi @Eli Guttman
You can use setTimeZone as below in a scoped application :
var now = new GlideDateTime();
gs.info("System Time is " + now);
var gsdt = new GlideScheduleDateTime(now);
gsdt.setTimeZone("Europe/London");
gs.info("London time is " + gsdt.getGlideDateTime().getDisplayValue());
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:29 AM
Hi, this solution did not work for me.
+ gsdt.getGlideDateTime().getDisplayValue()
Do not return the expected time according to the time zone i set.