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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 10:29 PM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 01:43 AM
Try to create a before - update BR like this one and add the following script:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 02:50 AM
Hello Ed`N,
Thanks for Reply on my requirement
but in my instance it's not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 03:09 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 03:54 AM