Timezone inconsistency when Scripting in Flow Designer Custom Actions

HasithaCNawal
Tera Contributor

Hi everyone,

I ran into a timezone issue when using GlideTime APIs inside a Flow Designer Custom Action script.

Scenario

  • User timezone: Europe/Helsinki

  • Script is written inside a Custom Action (Script step) in Flow Designer

  • I am using a GlideTime object and calling:

var gt = new GlideTime(someTimeValue);
var hour = gt.getHourLocalTime();

The returned hour was wrongTo investigate further, I checked the session timezone inside the script:

gs.getSession().getTimeZoneName();

Interestingly this returned:

America/Los_Angeles

Interestingly, when I run the same logic in Background Scripts, the timezone behaves correctly and respects the user's timezone.

 

Questions

Is this expected behavior because Flow Designer  run in a system execution context instead of the user’s session?

If so, what is the recommended way to correctly calculate user-local time (e.g., using getHourLocalTime()) inside Flow Designer scripts?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@HasithaCNawal 

when flow runs with system then it picks system timezone mostly America/Los_Angeles by default

background script uses the user's timezone who runs that script.

so always recommended to convert that to your timezone which you require

OR

Set the Flow to Run as User who initiated the session to pick that user's timezone

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@HasithaCNawal 

when flow runs with system then it picks system timezone mostly America/Los_Angeles by default

background script uses the user's timezone who runs that script.

so always recommended to convert that to your timezone which you require

OR

Set the Flow to Run as User who initiated the session to pick that user's timezone

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@HasithaCNawal 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Great. Thanks Ankur

@HasithaCNawal 

So how did you solve this?

It would be great if you share the approach and logic so that it helps other members in future

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader