- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 06:50 AM - edited ‎10-13-2022 06:50 AM
Hello Developers,
I have been trying to update to update userid which is on user table for 1000+records,
It is not taking correct format, I guess there is something wrong in the script.
I want to update userid as 'AZ123@company.com' , Could anyone suggest where should i make changes in the fix script so that script will successfully update the records that we have in our system,
I am using below script, for updating records via fix script
Fix Script:
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_domain', '');
gr.addQuery('first_name', 'Rest');
var ans = desc.match(/([A-Z][A-Z]|[a-z][a-z])-[0-9][0-9][0-9]|/gi);
gr.addQuery('last_name', ans);
gr.query();
if (gr.next())
{
var str = gr.user_name;
var res = str.replace('-', '');
var res = str.concat('@company.com');
gr.user_name = res;
gr.setWorkflow(false);
gr.update();
}
Any kind of help is highly appreciated here,
Thanks & Regards,
Ujjwala
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 07:01 AM - edited ‎10-13-2022 07:14 AM
Hi @Ujjwala1 ,
can you try this script. if loop will not work for bulk update
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_domain', '');
gr.addQuery('first_name', 'Rest');
var ans = desc.match(/([A-Z][A-Z]|[a-z][a-z])-[0-9][0-9][0-9]|/gi);
gr.addQuery('last_name', ans);
gr.query();
while (gr.next()) {
var str = gr.user_name;
var res = str.replace('-', '');
var res1 = res.concat('@company.com');
gr.user_name = res1;
gr.setWorkflow(false);
gr.update();
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 07:00 AM
Hi Ujjwala1
You want to update username in what format?Can you explain in detail of your requirement with few sample examples?
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 08:18 AM - edited ‎10-13-2022 08:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 07:01 AM - edited ‎10-13-2022 07:14 AM
Hi @Ujjwala1 ,
can you try this script. if loop will not work for bulk update
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_domain', '');
gr.addQuery('first_name', 'Rest');
var ans = desc.match(/([A-Z][A-Z]|[a-z][a-z])-[0-9][0-9][0-9]|/gi);
gr.addQuery('last_name', ans);
gr.query();
while (gr.next()) {
var str = gr.user_name;
var res = str.replace('-', '');
var res1 = res.concat('@company.com');
gr.user_name = res1;
gr.setWorkflow(false);
gr.update();
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 07:02 AM
Hi @Ujjwala1
What I understand from your requirement is that you just want to remove '-' hyphen from your user ID, right?
Else can you give sample if this is not right?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023