- 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-30-2017 12:53 AM
Hi Amol,
From your code I can assume that you are working on Scoped Application. If you would have mentioned it earlier the issue would have resolved long before. In scoped application you need to give a bit extra effort for Date/Time functionalities, like what you have done. But glad to know that you found the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 12:55 AM
Thank you Amlan appreciate your help
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 12:59 AM
Hi Amlan,
If it is a scoped application. What changes exactly. Can you explain more.
Regards
Param
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 03:04 AM
Hi,
In Scoped Application, you always need to instantiate a new GlideDateTime object with the field/variable value. If you look at Amol's response above, he has defined variable dt as var dt = new GlideDateTime(rec.u_project_id.end_date) instead of simply defining as var dt = rec.u_project_id.end_date. Again, if you want to get the value you need to use getDisplayValue() as he has used inside gs.print(). One more thing, gs.log() doesn't work in scoped application. So for this you need to use gs.print() or gs.warn() or gs.info().
For more details, I would encourage you to go through the methods and its examples in the below links:
1. Scoped GlideDateTime API Reference - ServiceNow Wiki
2. Scoped GlideTime API Reference - ServiceNow Wiki
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
09-19-2017 11:54 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: GlideDateTime
Visit http://docs.servicenow.com for the latest product documentation