I want to use gs.beginningOfToday() for a specific timezone.

KS18
Giga Guru

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?

9 REPLIES 9

In the Script Include, select "All application scopes" as Accessible from.

find_real_file.png

Example of executing from within a scope.

find_real_file.png

find_real_file.png

Thank you for telling me the case of ScriptInclude.
I want to use the scriptedAPI in a scoped application.
How do I do this?

Call the Script Include from Scripted API.

I've written an article (in Japanese) on Scripted REST API. There is an example of calling Script Include from Scripted REST API.

The example is in Global but can be used in scoped application too. Make Scripted REST API and Script Include in the same scope.

https://qiita.com/htshozawa/items/4d32e77bb4fd20358695

Hitoshi Ozawa
Giga Sage
Giga Sage

Script Include:

var DateTimeUtil10 = Class.create();
DateTimeUtil10.prototype = {
    initialize: function() {},
    getBeginningOfToday: function(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;
        return gdt.getDisplayValue();
    },
    getEndOfToday: function(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;
        return gdt.getDisplayValue();
    },
    type: 'DateTimeUtil10'
};

variable 1:Default value:

javascript: new DateTimeUtil10().getBeginningOfToday('Asia/Tokyo');

variable 2:Default value:

javascript: new DateTimeUtil10().getBeginningOfToday('America/Los_Angeles');

Execution result:

find_real_file.png