- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 05:35 AM
Hi,
I am trying to update about a 900 records (3 fields are being updated) in the user table and based on a condition.
I am thinking I will run a fix script (below) but since this I am fairly new to updating records via GlideRecord queries I wanted to see if the below looked right?
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('u_employee_type=Functional');
gr.setLimit(10);
gr.query();
while (gr.next()){
gr.active = true; //true-false field
gr.locked_out = false; //true-false field
gr.u_exit_date = ''; //date field
gr.update();
}
Thanks in advance,
Joshua Anderson
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 05:54 AM
Hi Joshua,
gr.setLimit basically limits the number of records that would be returned by glide record so in this case on 10 records would be returned and updated so that line is not required. Please use the code below:
- var gr = new GlideRecord('sys_user');
- gr.addEncodedQuery('u_employee_type=Functional');
- gr.query();
- while (gr.next()){
- gr.active = true; //true-false field
- gr.locked_out = false; //true-false field
- gr.u_exit_date = ''; //date field
- gr.update();
- }
The link below would be helpful in case plan to make any changes in your query:
Thanks,
Manik
PS - Please mark correct, helpful or like if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 05:56 AM
FYI Joshua, setLimit() is a good idea for testing here as it keeps your script from running away if the query is incorrect in some way. For the production release, you won't need/want it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:04 AM
Thanks for all the help everyone, it worked.
-Joshua Anderson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2016 08:15 AM
I'm trying to do basically the same thing. We created a new List type field in the incident table so that we can add multiple Business Units to an Incident. So now I need to just update all the records and set the new List field on the old Incidents with whatever was in the Business Unit field. I'm testing in my Dev environment and I only have 359 records, but when I loop through each record it only updates one record each time I run it. If I don't perform the update and just loop through, it will go through every record.
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
var aff_bu = gr.u_business_unit.getDisplayValue();
gr.u_affected_business_units = aff_bu;
gr.update();
}