How do I change data using a script to update a user field.

philkindrick
Kilo Contributor

We have changed our email domain and now I need to update all of my users. I would like to run a script that would find all of the @olddomain.com and replace it with @newdomain.

 

Can anyone assist me with this?

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Phil,



Here you go. Please run this from background script. Try this on your dev instance first.


var gr = new GlideRecord('sys_user');


gr.query();


while(gr.next())


{


var str = gr.email;


var res = str.replace("@olddomain.com", "@newdomain.com");


gr.email = res;


gr.setWorkflow(false);


gr.update();


}


View solution in original post

8 REPLIES 8

Yea, I did.



Here is something really strange though. I have updated the email addresses associated with the users but system notifications using field "caller_id" are still sending emails to the old domain.



I am really stumped here. There are zero references to the old domain in the system at this point...


Hi Phil,



Have you checked the Email properties to ensure the instance is referencing the right domain there?


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Phil,



Here you go. Please run this from background script. Try this on your dev instance first.


var gr = new GlideRecord('sys_user');


gr.query();


while(gr.next())


{


var str = gr.email;


var res = str.replace("@olddomain.com", "@newdomain.com");


gr.email = res;


gr.setWorkflow(false);


gr.update();


}


Teena Singh
ServiceNow Employee
ServiceNow Employee

Phil,


Glad to see that you are using the Community to learn more.


The Customer Experience team is striving to ensure that customer queries posted from the HI Service Portal are answered in timely and accurate fashion.


If you feel your question has been resolved, please mark the appropriate reply in the thread as being the Correct Answer.


This enables other customers to learn from your thread.


Thank you in advance.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Regards,


Teena Singh
Customer Experience: UX Strategy and Customer Insights
teena.singh@servicenow.com


ServiceNow


Screen Shot 2017-01-19 at 8.55.52 AM.png