Auto closure of Task after 3 business days

Gagandeep2
Mega Contributor

HI All,

 

I have a requirement that  if a task assignment group is XYZ and if Assigned to is NOT empty, I need to close the task marked "Closed Complete" within 3 Business Days (Monday to Friday between 9AM and 5PM) . Please guide

1 ACCEPTED SOLUTION

If this has solved your problem, kindly mark the comment as a correct answer so that the question is moved to the solved list.

Regards,
Asif
2020 ServiceNow Community MVP

View solution in original post

7 REPLIES 7

asifnoor
Kilo Patron

Hi,

Try like this.

var gdt = new GlideDateTime();
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery("assignment_group=sys_id^assigned_toISNOTEMPTY");
gr.query();
while(gr.next()) {
  //get the created date
  var created = new GlideDateTime(gr.sys_created_on);
  created.addDays(3); //add 3 days for comparing.
  if(created.onOrBefore(gdt)) {
    //close the task
    gr.state=3;
    gr.update();
  }
}

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

If this has solved your problem, kindly mark the comment as a correct answer so that the question is moved to the solved list.

Regards,
Asif
2020 ServiceNow Community MVP

is this a business rule?