Fix script to set task state with "closed - skipped" status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 10:03 AM
Hi All,
I have a requirement to set the state of the task to "closed - skipped" from backend. After setting the closed by and updated by shouldn't be disclosed.
How to achieve this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 10:12 AM
@phr Here is the code using which you can change the task state without updating closed by and updated by.
var task = new GlideRecord('task');
// Change all Open(1) incidents to Closed Skipped (7)
task.addQuery('state', 1); //Please apply the filter carefully
task.query();
while (task.next()) {
task.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
task.setWorkflow(false); // Do not run any other business rules
task.setValue('state', 7); //Closed Skipped state
task.update();
}
Caution: Since this query runs on task table (Parent of many tables) please exercise extreme caution and apply appropriate addQuery statement before running this query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 12:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 01:25 AM
@phr Glad that it worked, could you please mark the answer helpful and correct.