How to remove KB articles which are 5 years old, i tried Flow Designer but no use. Can you please help me.

teja25
Tera Contributor

Im trying to remove kb articles which are published more than 5 years, using flow designer. but no luck it is not picking up anything.find_real_file.png

this is the trigger im using,

as part of developing im trying to change to valid to certain date.

find_real_file.png

 

Please give me any suggestions if we can try another way.

6 REPLIES 6

Ruchit
Mega Sage

Use Background script to delete Knowledge article

 

delkb();

function delkb() {
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery(''); // Enter query from filter used in kb_knowledge
gr.setWorkflow(false);
gr.query();
while (gr.next()) {
gr.deleteRecord();
}
}

 Please mak thisas correct if this script is helpful to you.

teja25
Tera Contributor

this should run daily. check for 5 years kb and delete it. 

Ian Mildon
Tera Guru

You could use something similar to this in a scheduled job script execution:

var kbArticle = new GlideRecord('kb_knowledge');
kbArticle.addQuery('workflow_state', 'published');
kbArticle.query();
while (kbArticle.next()) {
    var diffDays = gs.dateDiff(kbArticle.u_review_date, gs.now(), true) / 86400;
    gs.log(kbArticle.number + "datediff" + diffDays);
    if (diffDays >= 365 && diffDays < 366) { //* introduce a little flexibility of diffDays result to allow for fractional calculations
        gs.eventQueue('unchc.notify.author.365', kbArticle, kbArticle.author, kbArticle.kb_knowledge_base.owner);
    }
}

Just modify the diffDays field check to suit and amount to be >= 5 years worth, and rather than trigger an email, update the records or delete them

OlaN
Giga Sage
Giga Sage

Hi,

You should change the trigger to run daily/weekly/monthly instead, and then delete the records by performing a lookup, and then do a for-each record, delete record.

Example below:

find_real_file.png