- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:00 AM
Hello all,
I have a requirement to add additional comments to multiple incident via fix script. Below is my fix script but when I run the script, comments was not added to all the incident. Please assist on what I am doing wrong why the comment are not added to the incidents. Thanks
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^priority=4');
gr.query();
if (gr.next()) {
gr.comments = 'Please reopen this incident.';
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:06 AM
Hello @Ken61
You are using if condition that's why it's not updating all the incidents
Please try below script -
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^priority=4');
gr.query();
while (gr.next()) {
gr.comments = 'Please reopen this incident.';
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:05 AM
Hi,
In your script you are using an if-statement to write the comment.
This will only process once, if the query returns true, and will write a comment on the first record.
If you want to process all the records, change that statement to a while-loop instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:16 AM
Some additional thoughts.
You might consider changing/adding to your query, to limit the results, in this case you will write a comment on ALL incidents that are active and has priority 4.
It doesn't seem logical to write a comment to reopen an incident which is already open?
There are no date limitations, so you might get really old incidents back, maybe you should only reopen a subset of all incidents?
Finally, avoid using "gr" as a variable name, use descriptive variable names instead (you will thank yourself later on).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:06 AM
Hello @Ken61
You are using if condition that's why it's not updating all the incidents
Please try below script -
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^priority=4');
gr.query();
while (gr.next()) {
gr.comments = 'Please reopen this incident.';
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 04:10 AM
Thank You @Harsh_Deep . It works now