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