- 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:25 PM
Hi Amol,
You may use updateMultiple() method. For reference please find section 11.2 here:
http://wiki.servicenow.com/index.php?title=Scoped_GlideRecord_API_Reference#updateMultiple.28.29
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:34 PM
Hi Amlan,
Its not working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:42 PM
Hi Amol,
Could you please try the below script:
var rec = new GlideRecord('u_test_plan');
rec.addQuery('u_request_status','canceled');
rec.addQuery('u_test_cancel_date','');
rec.query();
rec.setValue('u_test_cancel_date', rec.u_project_id.end_date); //You may set any static value as rec.setValue('u_test_cancel_date', 4);
rec.updateMultiple();
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2017 11:45 PM
Amlan,
Its a date value so not updating anything,
not working Amlan. Do it have any other method to do like converting date value to string and then assign?
Regards,
Amol Bavaskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 12:11 AM
Hi Amol,
I have crossed check the similar functionality in my instance via Background script and working fine. Please use the modified script below. Hope this will work in your instance too.
var gr = new GlideRecord('u_test_plan');
gr.addQuery('u_request_status', 'canceled');
gr.addQuery('u_test_cancel_date','');
gr.query();
while(gr.next()){
var cancel_date = gr.u_project_id.end_date;
gr.u_test_cancel_date = cancel_date;
gr.update();
}
I hope this helps. Please mark correct/helpful based on impact