Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set the time zone for the user session in a Business Rule ? - Scoped Application.

Gsahu
Tera Contributor

How to set the time zone for the user session in a Business Rule ? - Scoped Application.

Any suggestions please...

gs.getSession().setTimeZoneName("Asia/Kolkata");

Output:

 
Evaluator: org.mozilla.javascript.EcmaError: Cannot find function setTimeZoneName in object com.glide.script.fencing.ScopedGlideSession@e00b31.
   Caused by error in script at line 1

==>   1: gs.getSession().setTimeZoneName("Asia/Kolkata");

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sahu,

the glidesession class in scoped app doesn't have that method it seems

check links below

https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_refe...

https://snprotips.com/blog/2017/9/12/handling-timezones-in-servicenow-timezoneutil

https://gist.github.com/thisnameissoclever/b196fb32ccfeaebce919907af819d734

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Oleskii_Top
Tera Contributor

Hi, 

You can set session timezone from ScopedApp using TimezoneAjax ScriptInclude which located in Global scope but is available from other scopes. 

 

 

var userTZ=gs.getSession().getTimeZoneName();  //Save user timezone
var gTz=new global.TimezoneAjax();
gTz.changeTimeZone('US/Pacific');   // Set custom timezone 

// Do what you need

gTz.changeTimeZone(userTZ); //  Restore user timezone