The CreatorCon Call for Content is officially open! Get started here.

Background script to modify a User Name

tanumoy
Tera Guru

Suppose a User "ABC" is present in multiple fields of multiple tables within the instance. I want to replace "ABC" with "XYZ" in all those fields of all the tables at one go with a background script.

Can anyone help on this?

6 REPLIES 6

Bhagya Lakshmi
Mega Guru

Hi,

If the user field in multiple tables is reference to User table. Then you will change the name of the User in User table by using background script. If you change name in sys_user table then user field also changes in all tables.

"ABC" and "XYZ" are two different user. Changing the name in sys_user table will not help here.

Ct111
Tera Sage

Hi Tanumoy,

 

Ultimately it's a user name that you are changing it means it is referring to sys_user table so you can write the below script and make the changes everywhere to that specific user.


var gr = new GlideRecord('sys_user');
gr.addQuery('name','ABC');
gr.query();
if(gr.next())
{

if(gr.name == 'ABC')

gr.first_name = 'XYZ';
gr.last_name = '';
gr.name = gr.first_name + gr.last_name;
gr.update();
gs.print('Name of the table is '+gr.name+ 'and count was'+gr.name);

}

 

PLEASE mark my answer as CORRECT and HELPFUL if it served your purpose

"ABC" and "XYZ" are two different user. I don't want to change the name of "ABC" to "XYZ". I just want to replace the "ABC" from all other referenced table with "XYZ".