Delete Knowledge articles after 14 Days?

micky09
Tera Contributor

I have below Requirement Can any body help how can i achieve this

WHEN a user checks out a knowledge article

AND that article is checked out for more than 14 days old

THEN the system should delete the draft article

 

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi,

Based on your question, it is assumed you've enabled the 'Knowledge Management Advanced' plugin which provides the 'Check out' functionality.

You therefore need to manage the Knowledge versions (kb_version table).

There is no 'Check out date' to reference, so unless you've implemented something similar, we can obtain a very similar result set you're after by viewing versions that have not been updated over the last 14 days and are in the Draft state.

See below script. Please ensure you run this with the commented lines first so as to verify the records and count prior to actually deleting the record.

Copy this script and create a 'Fix Script' to run these. I assume this also is not a one off? Therefore you'd also need to run this as a scheduled job.

To help others, please mark correct and/or helpful.
Thanks,
Robbie

var count = 0;
var encQ = "sys_updated_onRELATIVELT@dayofweek@ago@14^knowledge.workflow_state=draft”;
var kbvGR = new GlideRecord('kb_version');
kbvGR.addEncodedQuery(encQ);
kbvGR.orderByDesc('sys_updated_on');
kbvGR.query();
while(kbvGR.next()){
kbvGR.setWorkflow(false); // Ensure no other Business rule or logic is triggered
gs.log('Article version to remove: ' + kbvGR.knowledge.number);
count++;
//un-comment the below line once you've verified the result set and count are correct and you are ready to delete the version records
//kbvGR.deleteRecord();
}
gs.log(‘Count:’ + count)

View solution in original post

3 REPLIES 3

Robbie
Kilo Patron
Kilo Patron

Hi,

Based on your question, it is assumed you've enabled the 'Knowledge Management Advanced' plugin which provides the 'Check out' functionality.

You therefore need to manage the Knowledge versions (kb_version table).

There is no 'Check out date' to reference, so unless you've implemented something similar, we can obtain a very similar result set you're after by viewing versions that have not been updated over the last 14 days and are in the Draft state.

See below script. Please ensure you run this with the commented lines first so as to verify the records and count prior to actually deleting the record.

Copy this script and create a 'Fix Script' to run these. I assume this also is not a one off? Therefore you'd also need to run this as a scheduled job.

To help others, please mark correct and/or helpful.
Thanks,
Robbie

var count = 0;
var encQ = "sys_updated_onRELATIVELT@dayofweek@ago@14^knowledge.workflow_state=draft”;
var kbvGR = new GlideRecord('kb_version');
kbvGR.addEncodedQuery(encQ);
kbvGR.orderByDesc('sys_updated_on');
kbvGR.query();
while(kbvGR.next()){
kbvGR.setWorkflow(false); // Ensure no other Business rule or logic is triggered
gs.log('Article version to remove: ' + kbvGR.knowledge.number);
count++;
//un-comment the below line once you've verified the result set and count are correct and you are ready to delete the version records
//kbvGR.deleteRecord();
}
gs.log(‘Count:’ + count)

Robbie
Kilo Patron
Kilo Patron

Hi,

Just circling back regarding your question. Did you implement the changes advised in my response?

To help others, please mark my response correct and/or helpful.

Thanks,
Robbie

 

Robbie
Kilo Patron
Kilo Patron

Hi,

Just circling back regarding your question. Did you implement the changes advised in my response?

To help others, please mark my response correct and/or helpful.

Thanks,
Robbie