How to get logged in users time zone in scoped app?

Priya Shekar
Giga Guru

Hi All,

We used to get logged in users time zone by "gs.getUser().getTZ();"

But in scoped app, we get "Evaluator: org.mozilla.javascript.EcmaError: undefined is not a function." error while using the above code.

Is there any alternative for getTZ()?

Thanks,

Priya

10 REPLIES 10

Deepak Ingale1
Mega Sage

I don't about scoped app, but below code you can try to get a logged in user timeZone if above code you mentioned does not work.



var gr = new GlideRecord('sys_user');


gr.get(gs.getUserID());


var timeZone = gr.time_zone; // variable timeZone will store the user time zone value, you can use it further for scripting.


Hi Deepak,



The code you mentioned doesn't work in the global app as well.. have u tried this code?



Thanks,


Priya


I did run it in scripts background and it printed the correct time zone for the user.


It wont print time zone if that is the system time zone


Else it worked



var gr = new GlideRecord('sys_user');


gr.get(gs.getUserID());


gs.print(gr.time_zone);


joseeduardo
Giga Expert

Hello , priyadarshini! try these:


var gr = gs.nowDateTime(); // date and time


or


var gr = gs.now() // Just time