If the Work Order Task is not closed/rejected within 5 days, it should automatically close.

Abhilasha G T
Tera Contributor

Hi Team,

 

How to achieve ,If the Work Order Task is not closed/rejected within 5 days, it should automatically close.

using Scheduled Jobs.

 

Regards,

Abhilasha G T

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi

please refer to the following video: https://www.youtube.com/watch?v=quZ0r9QcsaM

Maik

View solution in original post

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi

please refer to the following video: https://www.youtube.com/watch?v=quZ0r9QcsaM

Maik

Hi Maik,

 

Thank you for the reference video you have shared , but there will be constrains to close the WOT form ,some mandatory fields need to fill before closing the task,

there is a BR/Scripts for those mandatory fields , am not supposed to disable those scripts

so need the suggestion without disturbing those script how can achieve.

 

Regards,

Abhilasha G T

Prashant Ahire
Kilo Sage

@Abhilasha G T 

The above code is Tested just change the field names

    var taskGr = new GlideRecord('task');
    taskGr.addActiveQuery();
    taskGr.query();
    while (taskGr.next()) {
        var taskOpenedDate = taskGr.sys_created_on;

        var taskopen = new GlideDateTime(taskOpenedDate);
        var currentDate = new GlideDateTime();
        var differenceInDays = (currentDate.getNumericValue() - taskopen.getNumericValue()) / (1000 * 60 * 60 * 24);

        if ((taskGr.state != 3 && taskGr.state != 7) && differenceInDays >= 5) { // Check if not closed or rejected and open for more than 5 days
            //Perform automatic closure logic here
            taskGr.setValue('state', 6); // Set the state to 'Closed' (assuming '6' is the code for 'Closed')
            taskGr.update();
        }
    }

Please check and Mark Helpful and Correct if it really helps you.
Regards,
Prashant Ahire

Prashant Ahire
Kilo Sage

HI @Abhilasha G T  The above code is Tested just change the field names

 

var taskGr = new GlideRecord('task');
    taskGr.addActiveQuery();
    taskGr.query();
    while (taskGr.next()) {
        var taskOpenedDate = taskGr.sys_created_on;

        var taskopen = new GlideDateTime(taskOpenedDate);
        var currentDate = new GlideDateTime();
        var differenceInDays = (currentDate.getNumericValue() - taskopen.getNumericValue()) / (1000 * 60 * 60 * 24);

        if ((taskGr.state != 3 && taskGr.state != 7) && differenceInDays >= 5) { // Check if not closed or rejected and open for more than 5 days
            //Perform automatic closure logic here
            taskGr.setValue('state', 6); // Set the state to 'Closed' (assuming '6' is the code for 'Closed')
            taskGr.update();
        }
    }

 

Please check and Mark Helpful and Correct if it really helps you.
Regards,
Prashant Ahire