- 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:38 AM
Hello,
Try this
- var gr = new GlideRecord('sys_user');
- gr.addQuery('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();
- }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2016 05:42 AM
Hi Joshua,
Have you tried running this in scripts-background on your dev system to test?
You can also try to place a log statement below the gr.query() to see how many records were retrieved (don't forget you limited it to 10)
gs.log(gr.getRowCount() + ' rows retrieved.'):
This video may help you with your debugging.
Faster Server Side Script Development and Test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2016 05:48 AM
1.Comment out line 3. Script looks good.
2.Also please verify the choice value of "u_employee_type" field is "Functional" or not.
(Use value not the label of the choice)
Thanks,
Mihir
- 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.