- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:12 PM
Can help when I access a Knowledge Base and all articles displayed have a 'valid to' date after today should be inactive.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:08 PM
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
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:15 PM
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.
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:40 PM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:54 PM
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();
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:15 PM
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.