- 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 05:16 AM
Hi Kiruthika,
The serWorkflow() method accepts one argument: a boolean true/false value. This argument will determine whether business rules should be triggered by any database actions performed by your GlideRecord script. For example, if you make a change and call the update() method, calling setWorkflow() and passing in false will prevent any business rules that would normally be triggered by that update from running.
Below link can also give you more info.
GlideRecord - Scoped | ServiceNow Developers
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:53 AM
Hi,
Try below, Also please create fix script for such things instead of Background script and also run fix script in background.
var count = 0;
var inc = new GlideRecord('incident');
inc.addQuery('state' , '2');
inc.query();
while (inc.next()) {
count++;
inc.state = '1' ;
inc.setWorkflow(false);
inc.update();
}
}
gs.print("Total number of Incidents changed is " +count);
Regards,
Musab