- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:31 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:40 AM
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
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:37 AM
Hi,
Also update incident_state = 1;
Also remove quotes from inc.state = '1' ; and from other integer values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:40 AM
Hi Suvro,
If I remove ' ' then also same results, the same code is working for state On-hold(3) to In-progress(2).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:40 AM
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
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 04:49 AM
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!