- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:14 PM
Hi Experts,
I want to copy some date value from another table in bulk. i want to set a value for almost 4k records.
tried with,
1. rec.u_test_cancel_date = rec.u_project_id.end_date.getGlideObject();
2. rec.u_test_cancel_date = rec.u_project_id.end_date.getDisplayValue();
3. rec.u_test_cancel_date.setValue(rec.u_project_id.end_date);
but when i run this for bulk update in background script it will run for only one record and update only one record.
Do we have any other way to resolve this as it is not able to update all the records in a single run.
Regards,
Amol Bavaskar.
+91-9405444404
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:25 PM
Hi Julian,
Here is the script :
var rec = new GlideRecord('u_test_plan');
rec.addQuery('u_request_status','canceled');
rec.addQuery('u_test_cancel_date','');
//rec.setLimit(3);
rec.query();
gs.print("row :: "+rec.getRowCount());
while(rec.next()) {
rec.u_test_cancel_date = rec.u_project_id.end_date;
gs.print('Project_ID :: '+rec.u_project_id);
gs.print('End Date :: '+rec.u_project_id.end_date);
rec.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:23 PM
If you execute the update in a loop over the result set of a GlideRecord query, this should work. Can you post the whole script you tried?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:25 PM
Hi Julian,
Here is the script :
var rec = new GlideRecord('u_test_plan');
rec.addQuery('u_request_status','canceled');
rec.addQuery('u_test_cancel_date','');
//rec.setLimit(3);
rec.query();
gs.print("row :: "+rec.getRowCount());
while(rec.next()) {
rec.u_test_cancel_date = rec.u_project_id.end_date;
gs.print('Project_ID :: '+rec.u_project_id);
gs.print('End Date :: '+rec.u_project_id.end_date);
rec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:24 PM
Hi Amol,
You'll need to post your code here, as background scripts should handle this correctly. There must be a bug in your JavaScript.
I suggest you look at the example queries listed here: https://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/
Do you have a while (gr.next()) or something similar, to iterate thru the glide records in your code?
var gr = new GlideRecord('incident'); //Indicate the table to query from
//The 'addQuery' line allows you to restrict the query to the field/value pairs specified (optional)
//gr.addQuery('active', true);
gr.query(); //Execute the query
while (gr.next()) { //While the recordset contains records, iterate through them
//Do something with the records returned
if(gr.category == 'software'){
gs.log('Category is ' + gr.category);
}
}
Once your script executes, you might also need to use the limit () function to avoid timeouts or taxing your instance too much.
gr.setLimit(1000);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:37 PM
Hi Shiva,
I tried with setLimit(10);
still not copping value
Regards,
Amol