Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

gr.update() not working

Manikandan2
Kilo Expert

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. 

16 REPLIES 16

Yes i know it is for Description field. This is only updating for random 3 incidents

Instead of update, can you print and check which records are matching your below condition.

gr.addEncodedQuery("active=true^stateNOT IN6,7,8");

Manikandan2
Kilo Expert

I have upgraded to London instance recently. Not sure if it is because of the upgrade

Omkar Mone
Mega Sage

Hi 

Can you try this once ?

 

var arr=".";
gr = new GlideRecord('incident');
gr.addQuery('stateNOT IN6,7,8');
//gr.setLimit(2);
gr.query();
while (gr.next())
{
arr += gr.description;

gr.description = arr;
gr.update();
}

Hi,

 

This is setting the same description for all incidents now.