Not able to change Incident state from In-progress to New via Background script/Fix Script

Kiruthika J
Tera Contributor

Hi All,

I want to change Incident state from In-progress(2) to New(1) via background script/ Fix script.

var inc = new GlideRecord('incident');
inc.query();
while (inc.next()) {
var sta = inc.getValue('state');
if ((sta == '2')) {
inc.state = '1' ;
inc.update();
}
}

Getting Below Error. For other states it's working fine.

find_real_file.png

1 ACCEPTED SOLUTION

Mohit Kaushik
Mega Sage
Mega Sage

Hi Kiruthika,

Try to add setWorkflow(false) in your script as shown below:

var inc = new GlideRecord('incident');
inc.query();
while (inc.next()) {
var sta = inc.getValue('state');
if ((sta == '2')) {
inc.state = '1' ;
inc.setWorkflow(false);
inc.update();
}
}

 

Please mark this as correct and helpful if it resolved the query or lead you in right direction.

Thanks,
Mohit Kaushik
Community Rising Star 2022

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

View solution in original post

6 REPLIES 6

suvro
Mega Sage
Mega Sage

Hi,

 

Also update incident_state = 1;

Also remove quotes from inc.state = '1' ; and from other integer values

Hi Suvro,

If I remove ' ' then also same results, the same code is working for state On-hold(3) to In-progress(2).

Mohit Kaushik
Mega Sage
Mega Sage

Hi Kiruthika,

Try to add setWorkflow(false) in your script as shown below:

var inc = new GlideRecord('incident');
inc.query();
while (inc.next()) {
var sta = inc.getValue('state');
if ((sta == '2')) {
inc.state = '1' ;
inc.setWorkflow(false);
inc.update();
}
}

 

Please mark this as correct and helpful if it resolved the query or lead you in right direction.

Thanks,
Mohit Kaushik
Community Rising Star 2022

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

The code which you have provided is working.

Could you please explain what the below line of code does here?

inc.setWorkflow(false);

Thanks!