- 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 08:24 AM
Hi, I had imported some user records on user table, because of that user_name took value same as email
Now, I want to update it as in this format 'AZ123@copado.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2022 09:04 AM
Hi Ujjwala,
How to update multiple records
1. Navigate to the list view of the table whose records you want to update. Tip: Just type the tablename.list into the navigator, like incident.list, to quickly get to this view.
In this example, we want to replace all occurrences of a monitoring tool's alert with a human readable description. ServiceNow's Event Management would have this normalization/transformation built in - but for the sake of this example let's assume it's a manual integration set up by an admin.
2. Now, it is crucial to decide - will you be updating all records on that table, or only a subset? If your answer is only a subset, make sure to apply filters so that only the data you want to update remains. If you want to update all records in the table, simply skip to step 3, but be aware that very large data sets will take a long time. In our example, we will filter on incidents where the short description is a particular monitoring string.
3. Once you have the data you would like to update, right-click any column title in List v2 (or select the three-line icon in List v3) and select Update All. This will update all the current records that match the filter criteria. It will not update records outside of the filter criteria.
On the other hand, Update Selected will only update the currently checked records, which is useful for smaller, manually selected batches.
4. You will see a confirmation message indicating the number of records that will be updated. This number should match the number of records in the list view at time of conducting the update (post-filter). This is a quick way to validate that you are not accidentally overwriting more records than you expected!
5. You will now see a blank form view of the records you are attempting to update. Set any new values you desire here, as they will be set across all the selected records. If you are missing the field you want to update, right-click the record header, navigate to Form Design (or Form Layout), and move the missing field onto the form (default view). After the update you can remove the field.
Please mark helpful if it helps you out,
Thank you,
Omkar