Auto-Close Knowledge Feedback Tasks

Roy Barclay
Tera Contributor

I am trying to create a scripted enhancement in ServiceNow to Auto-Close Knowledge Feedback Tasks (KFTs) after 5 Days in "Resolved" State

 

Script I have generated thus far:

var kft = new GlideRecord('kb_feedback_task');

kft.addEncodedQuery('state=4');

kft.query();

while (kft.next()) {

    var date = gs.nowDateTime();

    var dur = gs.dateDiff(kft.u_resolved, date, true);

    var convertsecondstodays = parseInt(dur) / (60 * 60 * 24);

    if (convertsecondstodays >= 5) {

        kft.state = '10';

        kft.active = false;

        kft.update();

    }

}

 

Any assistance or recommendations that you might have would be greatly appreciated.

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

You can use below logic as well.

var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-5);
var kft = new GlideRecord('kb_feedback_task');
kft.addEncodedQuery('state=4');  // 6 is resolved as per OOB setup
kft.addQuery('u_resolved_at', '<', queryTime);
kft.query();
while (kft.next()) {
        kft.state = '10';  // 3 is closed as per OOB setup
        kft.active = false;
        kft.update();
}

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

nidhi_Community
Tera Contributor

Hi  @Anil Lande 

when I this script it's closing incident next after resolved while I am using addDaysUTC(-5) and same script