Background script to modify a User Name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 01:39 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 02:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 03:35 AM
"ABC" and "XYZ" are two different user. Changing the name in sys_user table will not help here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 02:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 03:38 AM
"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".