Make a knowledge article inactive, if it has no activity for a year / 365 days

muhammad4
Tera Contributor

how can i have a scheduled job check for knowledge articles with no activity. I would like to ensure that published Knowledge Articles with a "valid to" date of  before today or not updated in more than a year are made inactive and are not available in the relevant KB

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

Please update your Scheduled job script as below:

retireArticles();

function retireArticles(){
	var gr = new GlideRecord('kb_knowledge');
	gr.addEncodedQuery('workflow_state=published^valid_to<javascript:gs.beginningOfToday()^sys_updated_onRELATIVELT@year@ahead@1');
	gr.query();
	while(gr.next()){
		gr.workflow_state = 'retired';
		gr.active = false;
		gr.setWorkflow(false);
		gr.update();
		
	}
}

Alternatively, you can also use Flow Designer which is a no code approach to do the similar activity.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

Tudor
Tera Guru

Hi,

I believe you will require something like:

var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("valid_to<javascript:gs.beginningOfToday()^sys_updated_on<=javascript:gs.beginningOfOneYearAgo()");
kb.query();
while (kb.next()){
kb.active=false;
kb.update();
}

 

Now what are your trigger conditions that is for you to evaluate.

Hope this helps!

 Tudor

muhammad4
Tera Contributor

Thanks for sharing this, but it seems that the articles still say active.

Hi you cant make knowledge articles inactive. You need to retire the kb article . Making retired will not display articles on the portal or native UI.

var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("valid_to<javascript:gs.beginningOfToday()^sys_updated_on<=javascript:gs.beginningOfOneYearAgo()");
kb.query();
while (kb.next()){
kb.active=false;
kb.workflow_state = 'retired';
kb.update();
}

Regards
Harish

shloke04
Kilo Patron

Hi,

Please update your Scheduled job script as below:

retireArticles();

function retireArticles(){
	var gr = new GlideRecord('kb_knowledge');
	gr.addEncodedQuery('workflow_state=published^valid_to<javascript:gs.beginningOfToday()^sys_updated_onRELATIVELT@year@ahead@1');
	gr.query();
	while(gr.next()){
		gr.workflow_state = 'retired';
		gr.active = false;
		gr.setWorkflow(false);
		gr.update();
		
	}
}

Alternatively, you can also use Flow Designer which is a no code approach to do the similar activity.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke