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

sachin_namjoshi
Kilo Patron
Kilo Patron

Create schedule job from it to automatically close any catalog task (sc_task) that has been set to a status of Resolve for greater than 3 days.   

 

 

autoCloseSc_task();


 


function autoCloseSc_task() {


 


    var ps = gs.getProperty('glide.ui.autoclose.time');


    var pn = parseInt(ps);


    if (pn > 0) {


       


          var gr = new GlideRecord('sc_task');


          gr.addQuery('state', '10');


          gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));


          gr.query();


          while (gr.next()) {


                gr.state = '3';


                gr.work_notes = 'Task automatically closed after ' + pn + ' days in the Resolved state.';


                gr.active = false;


                gr.update();


          }


    }


}

 

Regards,

Sachin

 

As it is based on a condition, I have to do it with Business rule I believe

you can use same code in business rule as well.

 

Regards,

Sachin

Jaspal Singh
Mega Patron
Mega Patron

Hi Gagandeep,

 

You can create a scheduled job as below considering you have a Schedule that runs Mon-Friday 9-5 just copy the sys_id of schedule & replace it below

gs.include('DurationCalculator');
var gdt = new GlideDateTime();
var target = new GlideRecord('yourtablename'); //Replace table here
target.addQuery('assigned_to', ''); //Checks if assigned_to is empty
target.addQuery('assignment_group.name','XYZ'); //Replace name here correctly
target.query();
while (target.next()) {
    var dc = new DurationCalculator();
    dc.setSchedule('e40528d51bdfe7008009eb186e4bcbf8'); //pass sys_id of schedule that is Mon-Fri 9-5
    var secdf = dc.calcScheduleDuration(target.sys_created_on.getDisplayValue(), gs.nowDateTime());
    if (secdf > 60 && secdf < 161999) { // Greater than 3 Days.	
        if (target.state != 3) //3 is close but the state is not closed so close it below
        {
            target.state = 3; //close it & update
            target.update();
        }
    }
}

 

Only issue I find it you will have to make it run twice or once per day so as to make tickets change state to close accordingly. Similar was the case where I did use workflow but & timer activities but above as well should work.