I want to auto reflecting Time zone in user table from cmn_location Table Time Zone Field. For EX: If I set any Time Zone in cmn_Location Table that time zone reflecting in user table for particular user who are belongs to that time zone.

keval3
Tera Contributor

Hello All,

I want to auto reflecting Time zone in user table from cmn_location Table Time Zone Field.

For EX: If I set any Time Zone in cmn_Location Table that time zone reflecting in user table for particular user who are belongs to that time zone.

plz let me know if any one have any idea about my Requirement

Thanks & Regards

Keval

9 REPLIES 9

Ed13
Tera Contributor

Try to create a before - update  BR like this one and add the following script: 

find_real_file.png

   var tz = current.time_zone.toString();
	
	var grUser = new GlideRecord('sys_user');
	grUser.addEncodedQuery('location=' + current.sys_id);
	grUser.query();
	
	while(grUser.next()) {
		grUser.setValue('time_zone',tz);
		grUser.update();
	}

 

It worked in my PDI, let me know if it works for you. 

 

Thanks,

Ed`N

keval3
Tera Contributor

Hello Ed`N,

Thanks for Reply on my requirement

but in my instance it's not working 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

so users belonging to that Location should have the timezone set on location record?

you can use after update BR on location table

I assume your choice values are same for both the fields on both the tables

You can use updateMultiple() which is much faster

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_user");
	gr.addQuery("location", current.sys_id);
	gr.setValue('time_zone', current.time_zoneLocationField); // give here the field name present on location table
	gr.updateMultiple();

})(current, previous);

Regards
Ankur

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

Hi Ankur,

I tried your script but it is not working in my instance I put the screen sort please check and let me know.

 

find_real_file.png