Fix script to set task state with "closed - skipped" status

phr
Tera Contributor

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?

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@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.

Hi @Sandeep Rajput 

 

Thank you, this worked.

@phr Glad that it worked, could you please mark the answer helpful and correct.