- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:05 PM - edited 03-06-2025 10:06 PM
Hello!
I have a requirement to populate the timezone field in the Users table from the timezone field in the Location table.
However, the client does not use the Location reference field in the Users table. They created a text field and want to use this. I've created a before BR but does not work.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:16 PM - edited 03-06-2025 10:19 PM
Hi @ramirch
Add update(); in your script if that not works, verify with below updated script:
var gr = new GlideRecord('cmn_location');
gr.query();
while (gr.next()) {
if (current.u_location == gr.full_name) {
current.time_zone = gr.time_zone;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:16 PM - edited 03-06-2025 10:19 PM
Hi @ramirch
Add update(); in your script if that not works, verify with below updated script:
var gr = new GlideRecord('cmn_location');
gr.query();
while (gr.next()) {
if (current.u_location == gr.full_name) {
current.time_zone = gr.time_zone;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:22 PM
Hi @ramirch , Please try this:
var loc = current.getValue('u_location');
var gr = new GlideRecord('cmn_location');
gr.addQuery('full_name', loc);
gr.query();
if(gr.next()) {
if (gr.time_zone)
current.setvalue('time_zone', gr.time_zone);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:30 PM
remember time_zone field has choices in it.
Is user entering the correct choice value in u_location field?
if yes then simply use this
current.time_zone = current.u_location;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:32 PM
if user is entering location name then query location table and then get the timezone and set it
assuming they enter correct location name then use this
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("cmn_location");
gr.addQuery("u_name", current.u_location);
gr.query();
if (gr.next()) {
current.time_zone = gr.time_zone;
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader