to ensure that published Knowledge Articles with a "valid to" date of before today are made inactive.

Mad3
Tera Expert

Can help when I access a Knowledge Base and all articles displayed have a 'valid to' date after today should be inactive.

1 ACCEPTED SOLUTION

In that case you can use encodedQuery.

var query = 'kb_knowledge_base=a7e8a78bff0221009b20ffffffffff17^ORkb_knowledge_base=862c887e07d20110f1cbf48f7c1ed0c5';

var nowDate = new GlideDate().getDisplayValue();
var gr = new GlideRecord('kb_knowledge');

gr.addEncodedQuery(query); //you can add knowledge base sysid here 
gr.addQuery('valid_to',  '<', nowDate);
gr.query();
while(gr.next()){
gr.setValue('active', false);
gr.update();
}

Refer screenshot to run query

Regards
Harish

View solution in original post

14 REPLIES 14

Harish KM
Kilo Patron
Kilo Patron

Hi your question is not clear. You want to set knowledge articles in active before 1 day of valid to date? why you want to inactive a aritcle which is not expired?

The best approach is to retire the knowledge article. This way you can publish it again.

Regards
Harish

Thanks Harish,

The published knowledge articles which are reached the valid date those should be made inactive ( ex:- articles reached valid date to today from tomorrow should be made inactive)

Hi you can retire those knowledge articles. Retiring article users will not be able to search them. Have a schedule job to run daily to check valid to date. if doesnt match set them to retire

Script:

var kb = new GlideRecord('kb_knowledge');
kb.addQuery('workflow_state','!=','retired');
kb.addQuery('valid_to','<',gs.now()); // date check not valid
kb.query();
while(kb.next()){
var workflow = new Workflow();
workflow.cancel(kb); //this will cancel all workflow contexts with the record
kb.workflow_state = 'retired'; // set article to retired
kb.retired = gs.now();
kb.update();
}

Regards
Harish

Hello Harish,

Thank you for reply the above schedule job is working, But I need to write the schedule job for specific scope and we don't have choice to write schedule job on studio, have to write on Dev main page on "kb_knowledge" base. from the knowledge base I need to write on specific scope.

var nowDate = new GlideDate().getDisplayValue();
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('valid_to',  '<', nowDate);
gr.query();
while(gr.next()){
gr.setValue('active', false);
gr.update();
}

I wrote this it's working fine, and it is applicable for all knowledge base articles (shouldn't apply for all articles), I want to apply only a specific scope which we are working for specific scope.

Can you please help me on this.