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

Ajaykumar1
Tera Guru

What do you need to set in your description field......? Your code will set a dot in description field of all open/active incidents having state not one of resolved/closed/canceled.

Regards,
Ajay

Yes that is what i want to see. a dot in the description field of all tickets

I tried the code in my dev instance it's working fine.

You have to write the code in background script.

Regards,
Ajay

Hi,

I just ran your latest code and could see dot appended for the description of all incidents.

Don't you see dot in the description field? Kindly note its a description where you are adding . and not in short_description.

Run this code in background and see if it is showing description with the dot.

var gr = new GlideRecord('incident');
gr.addEncodedQuery("active=true^stateNOT IN6,7,8");
gr.query();
while (gr.next()) {
gr.description = gr.description + '.';
gs.print("Description is "+gr.description);
gr.update();
}