I want to use gs.beginningOfToday() for a specific timezone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 06:45 PM
I want to use gs.beginningOfToday() for a specific timezone.
I want to use javascript:gs.beginningOfToday()@javascript:gs.endOfToday() in a script to get the records created today.
As far as I know, the timezone for javascript:gs.beginningOfToday()@javascript:gs.endOfToday() depends on the timezoneof the user running that script.
If I want to get it in a specific timezone regardless of the user's timezone, what do I need to do?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 07:30 PM
Sample code:
getBeginningDateTime("Asia/Tokyo");
getBeginningDateTime("America/Los_Angeles");
getBeginningDateTime("America/Chicago");
function getBeginningDateTime(timezone) {
var today = gs.beginningOfToday();
var gdt = new GlideDateTime(today);
var tz = Packages.java.util.TimeZone.getTimeZone(timezone);
gdt.setTZ(tz);
var tzDiff = gdt.getTZOffset() /1000/ 60/60;
gs.info( gdt.getDisplayValue() + " " + timezone+ " " + tzDiff);
}
Execution result:
*** Script: 2022-02-09 00:00:00 Asia/Tokyo 9
*** Script: 2022-02-08 07:00:00 America/Los_Angeles -8
*** Script: 2022-02-08 09:00:00 America/Chicago -6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 09:04 PM
Thank you for your comment.
I get the following error when I try to implement this in a scoped application script.
java.lang.SecurityException: Use of Packages calls is not permitted in scoped applications
Caused by error in sysauto_script
Can I use this script only in Global?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 09:17 PM
Calling java package is only allowed in Global. That is, prefix the class name with "Global."
Try the following.
var today = new global.DateTimeUtil10().getBeginningOfToday();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 11:02 PM
Thank you for you comment, but it's not working in my environment.