- 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-28-2022 10:22 PM
HI I think you can use the below query to check application scope
gr.addQuery('kb_knowledge_base.application', 'scope here');
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:26 PM
Hi,
In the place of 2nd line have add.
var nowDate = new GlideDate().getDisplayValue();
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('kb_knowledge_base.application', 'scope here');
gr.addQuery('valid_to', '<', nowDate);
gr.query();
while(gr.next()){
gr.setValue('active', false);
gr.update();
}
Is correct..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:27 PM
I don't have much knowledge on scripting.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:37 PM
What is your specific scope? Basically knowledge articles are global so we can do query based on Knowledge base if each specific scope has a separate knowledge base or knowledgebase created on that scope
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:40 PM