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

HI I think you can use the below query to check application scope

gr.addQuery('kb_knowledge_base.application',   'scope here');

 

Regards
Harish

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..?

I don't have much knowledge on scripting.

 

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

Regards
Harish

2 Knowledgebases is created on the scope. Can see in attachment.