gr.update() not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 02:48 AM
Hi,
gr = new GlideRecord('incident');
gr.addQuery('stateNOT IN6,7,8');
gr.query();
while (gr.next()) {
gr.description = gr.description + '.';
gr.update();
}
The above is a small code i am writing to update all open incidents(anything except Resolved, Closed, Cancelled) state with a " . " in the description
When i run this query in the scripts background it is randomly updating only few tickets and it is not updating all tickets.
I am not sure what wrong i am doing here. What change should i make in this query to update all the incidents.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 03:49 AM
This is the result I got. I had limited the result set to 4 for testing.
var incidentGR = new GlideRecord('incident');
var oldDescription = '';
incidentGR.addEncodedQuery('stateNOT IN6,7,8');
incidentGR.setLimit(4);
incidentGR.query();
while(incidentGR.next())
{
oldDescription = incidentGR.description;
incidentGR.description = incidentGR.description + '.';
incidentGR.update();
gs.log('Incident ' + incidentGR.number + ' has been updated. Old Description: ' + oldDescription + '. New Description: ' + incidentGR.description);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2019 03:53 AM
Hi Manikandan,
The issue seems to be in your addQuery function. addQuery expects the following parameters: name, operator(optional), and value. In your script you are passing the query string.
To use addQuery in your case it would look like this
gr.addQuery('state','NOT IN','6,7,8');
To use it in the query format you have you would need to use an addEncodedQuery which expects the actual query string which can be grabbed from a list view by right clicking the filter and closing "Copy query".
To use addEncodedQuery in your case it would look like this
gr.addEncodedQuery('stateNOT IN6,7,8');
A working solution using addEncodedQuery would look like this
var gr = new GlideRecord('incident');
gr.addEncodedQuery('stateNOT IN6,7,8');
gr.query();
while (gr.next()) {
gr.description = gr.description + '.';
gr.update();
}
Thanks,
Brent
If this helps please mark as helpful or correct so that others may benefit from this information as well.