Populating timezone in User table

ramirch
Tera Contributor

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.

 

var gr = new GlideRecord('cmn_location');
gr.query();

 while (gr.next()) {

        if (current.getValue('u_location') == gr.getValue('full_name')) {
            current.setvalue('time_zone', gr.time_zone);
        }
    }
 
Please help!
Thank you.
1 ACCEPTED SOLUTION

Nilesh Pol
Tera Guru

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; 
}
}

 

View solution in original post

7 REPLIES 7

@ramirch 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@ramirch 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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

@ramirch 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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