Autoclose Knowledge Feedback tasks

kumar junior11
Tera Contributor

When a KB Feedback Task has been in the Resolved State for more than 2 Days (48 Hours), it should be automatically moved to the Closed state. help me  with the best solution.

 

 

thanks in advance,

regards

saikumar

16 REPLIES 16

kumar junior11
Tera Contributor

Hi @Robbie , @Mark Manders im using the below scheduled job script to close the kft tasks based on sate is 'resolved' and and the field 'updated on'. but i missing something here . if any one has logic for these help me with these.

im using 40 minutes in place of days to test.

autoCloseKBF();

function autoCloseKBF() {
    var minutesToWait = 40; // Set the time to wait in minutes
    var queryTime = new GlideDateTime();
    queryTime.addMinutesUTC(-minutesToWait);

    var kft = new GlideRecord('kb_feedback_task');
    kft.addEncodedQuery('state=6^sys_updated_on<javascript&colon;gs.dateGenerate('+queryTime.getYear()+','+queryTime.getMonth()+','+queryTime.getDayOfMonth()+','+queryTime.getHourOfDay()+','+queryTime.getMinutes()+','+queryTime.getSeconds()+')'); // Use encoded query to check for both state and sys_updated_on
    kft.query();

    while (kft.next()) {
        var updatedTime = new GlideDateTime(kft.sys_updated_on);
        if (updatedTime.before(queryTime)) { // Check if sys_updated_on is before the query time
            kft.state = '3'; // Set the state to '3' to represent 'Closed'
            kft.active = false;
            //kft.work_notes.setJournalEntry('Feedback Task automatically closed after ' + minutesToWait + ' minutes in the Resolved state.'); // Uncomment if you wish to add a worknote - recommended.
            //kft.setWorkflow(false); //uncomment this line if you don't want to trigger other business rules/log etc
            kft.update();
        }
    }
}
Spoiler
Spoiler
Spoiler
 

Mark Manders
Mega Patron

Why are you making it so difficult? Run it once a day and create your encoded query for the selection of tasks on 'state is resolved AND resolved_at before 2 days ago'. It will close all of the tasks that are (over) 2 days on the resolved state. We're talking about feedback tasks. On these it shouldn't matter if they are on resolved for 48 hours or for 71 hours and 59 minutes (which is the max when running it once a day).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark