How to update incident impact and urgency via background script

attanhes
Tera Guru

I am trying to bulk update incident priority via a background script. To update the priority in my instance, I need to set the impact and urgency. When I update the records via the background script below, I get some errors,which I can't figure out. But at the same time the ticket priority gets updated to Priority 4.

 

 

////Change the priority of active incident
var gr = new GlideRecord('incident');
gr.setLimit(5); //limit only first  2 record 
gr.addQuery('type', 'incident');
gr.addQuery('active', true);
gr.addQuery('priority', '3');
gr.addQuery('u_urgent_p3',false);
gr.query();
gs.print(gr.getRowCount());//Count the record numbers 
while(gr.next())
{
//shift the priority from P3==>P4
gr.impact = 3; // Set impact to 3 - Low
gr.urgency = 2; // Set urgency to 2 - Medium
//gr.work_notes = 'The priority of this ticket has been adjusted (P3 -> P4)';
//gr.setValue('impact', '3'); // Set impact to 3 - Low
//gr.setValue('urgency', '2'); // Set urgency to 2 - Medium
gr.setWorkFlow(false);//stop firing BR
gr.update();
gs.print(gr.number + ', Priority: ' + gr.priority);//Print the record number
}

 

 

 

Error eg:-

 

 

*** Script: 5
Invalid query string received:4,-30,-40,3,-10,6: null
Invalid query string received:4: null
Invalid query string received:Incident: null
Invalid query string received:7: null
Slow business rule 'Run SLAs' on incident:<span class = "session-log-bold-text"> INC0087611</span>, time was: 0:00:00.417
*** Script: INC0087611, Priority: 4
Invalid query string received:4,-30,-40,3,-10,6: null
Invalid query string received:4: null
Invalid query string received:Incident: null
Invalid query string received:7: null
Slow business rule 'Run SLAs' on incident:<span class = "session-log-bold-text"> INC0089362</span>, time was: 0:00:00.496
*** Script: INC0089362, Priority: 4

 

 

 

2 ACCEPTED SOLUTIONS

Maik Skoddow
Tera Patron

The problem is the type with disabling Workflows, therefore they are still running in the background causing some error messages.

Instead write (with a lower "f")

gr.setWorkflow(false)

  

View solution in original post

SN_Learn
Kilo Patron

Looks like , instead of setWorkflow(false) you are using setWorkFlow(false) which is causing the issue due to incorrect syntax.

gr.setWorkFlow(false);//stop firing BR

Correct:

gr.setWorkflow(false);//stop firing BR

 

Please mark my answer as correct and helpful based on Impact.

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

7 REPLIES 7

Maik Skoddow
Tera Patron

The problem is the type with disabling Workflows, therefore they are still running in the background causing some error messages.

Instead write (with a lower "f")

gr.setWorkflow(false)

  

Hi @attanhes 

may I ask why you have not marked my answer as correct, although it was give first and also correct?

My apologies. I was trying to figure out where the error was in my code even though you clearly explained how to fix it. I was totally blind to it or long day..

From second post, I clearly saw my error.

 

However, I really appreciated both of your posts and I have marked your answer also accepted as solution.

SN_Learn
Kilo Patron

Looks like , instead of setWorkflow(false) you are using setWorkFlow(false) which is causing the issue due to incorrect syntax.

gr.setWorkFlow(false);//stop firing BR

Correct:

gr.setWorkflow(false);//stop firing BR

 

Please mark my answer as correct and helpful based on Impact.

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.