Change Timezone via Script

Naveen87
Tera Guru

Hey Guys,

 

I have to update time zone for specific client. There are 1300 user under that client.

Manual task would take too much time. Can't move XML to UAT & PROD due to sys_id mismatch.

Is there any script that can be run and change time zone?

If yes please help me or provide any suggestion to reduce this manual task.

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use and run below fix script to change time zone for existing users.

 

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery();//query to find out user records to update
gr.query();
while (gr.next()) {
   
      gr.time_zone = 'Canada/Pacific'; // you can get these values from sys_choice table for time_zone field like https://<<<your_instance_name>>>.service-now.com/sys_choice_list.do?sysparm_query=element%3Dtime_zone%5Ename%3Dsys_user&sysparm_view=
      gr.setWorkflow(false); // Don't run business rules for this update
      gr.update();
   
}

 

Regards,

Sachin

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use and run below fix script to change time zone for existing users.

 

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery();//query to find out user records to update
gr.query();
while (gr.next()) {
   
      gr.time_zone = 'Canada/Pacific'; // you can get these values from sys_choice table for time_zone field like https://<<<your_instance_name>>>.service-now.com/sys_choice_list.do?sysparm_query=element%3Dtime_zone%5Ename%3Dsys_user&sysparm_view=
      gr.setWorkflow(false); // Don't run business rules for this update
      gr.update();
   
}

 

Regards,

Sachin

Hi,

 

Thank you .

 

Tested for 1 user. 

It's working.

 

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_domainLIKEryder^user_nameSTARTSWITHVarity_Randall@ryder.com');//query to find out user records to update
gr.query();
while (gr.next()) {

gr.time_zone = 'Europe/London'; // you can get these values from sys_choice table for time_zone field like https://<<<your_instance_name>>>.service-now.com/sys_choice_list.do?sysparm_query=element%3Dtime_zone%5Ename%3Dsys_user&sysparm_view=
gr.setWorkflow(false); // Don't run business rules for this update
gr.update();

}

Hi,

 

Where do we run this script and is there conditions?

 

Can I use below:

gr.time_zone = current.location.time_zone;

 

Thanks

Chin

Kathiresan S
Tera Contributor

Hi,

You can refer the below link to convert timezone :

Convert Timezone 

 

Thanks,
Kathiresan S

 

Please mark this as correct and helpful if it resolves the query or leads you in the right direction.



Thanks,
Kathiresan S