- 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:53 PM
var nowDate = new GlideDate().getDisplayValue();
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('kb_knowledge_base', 'sysID of knowledgebase'); //you can add knowledge base sysid here
gr.addQuery('valid_to', '<', nowDate);
gr.query();
while(gr.next()){
gr.setValue('active', false);
gr.update();
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 11:05 PM
In that case we have 2 knowledge bases. So how can add 2 sys id's of knowledge base.

- 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-29-2022 07:35 AM
Thanks Harish,
that really helped me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 11:18 PM
Hey,
You can follow below article to understand the working of Valid to:
For knowledge articles, what will happen after the “valid to “date is passed?
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar