- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 11:01 AM
I want to write a fix script for doing a bulk update in the indicator task table into a particular field.The table is IDT. The tasks are already closed, so the field is grayed out. Below is the code that I have written.
var gr = new GlideRecord('table name');
gr.addEncodedQuery('the query for the tasks that needs to be updated.');
gr.query();
while(gr.next()){
gr.fieldname = "the update";
gr.setWorkflow(false);
gr.update();
}
After I run the script I find that no changes has happened in the required field. It still shows blank.
Any help will be appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 12:14 PM
Hello Sayan,
I hope you are actually running the correct code. This below code will not work as is. you need to place right field names and right queries.
var gr = new GlideRecord('table name');
gr.addEncodedQuery('the query for the tasks that needs to be updated.');
gr.query();
while(gr.next()){
gr.fieldname = "32 digit sys_id that you need to update";
gr.setWorkflow(false);
gr.update();
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 11:57 AM
Guys, I have seen this question around 6 times in last 1 hour. Please remove all these duplicate post and post it only once so that people can help you and you can get the answer quickly.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 12:02 PM
Hi Sayan,
If its a reference field, then you need to mention the sys_id in that field. ARe you setting the sys_id correctly?
Is the code entering the while loop? check once.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 12:09 PM
Yes its entering the while loop. Please be more specific with sys_id. a coding example will be more helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2020 12:14 PM
Hello Sayan,
I hope you are actually running the correct code. This below code will not work as is. you need to place right field names and right queries.
var gr = new GlideRecord('table name');
gr.addEncodedQuery('the query for the tasks that needs to be updated.');
gr.query();
while(gr.next()){
gr.fieldname = "32 digit sys_id that you need to update";
gr.setWorkflow(false);
gr.update();
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP