How to retrieve the knowledge articles based on the valid to

GBS
Tera Contributor

I’m using the background script below to get the articles that will expire in 2 months from now, I have tried with encoded query but none are working. Can anyone help me with this

 

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('workflow_state', 'published');
gr.addQuery('kb_knowledge_base.title', 'HR');
gr.addEncodedQuery();
gr.query();

if (gr.hasNext()) {
    gs.print('Articles expiring after the end of this month:');
    while (gr.next()) {
        var kbName = gr.kb_knowledge_base.getDisplayValue();
        gs.print('Article Number: ' + gr.number);
        gs.print('Title: ' + gr.short_description);
        gs.print('Knowledge Base: ' + kbName);
        gs.print('Expiration Date: ' + gr.valid_to);
        gs.print('----------------------------------');
    }
} else {
    gs.print('No articles found expiring after the end of this month.');
}
1 ACCEPTED SOLUTION

Hello @GBS 

In that case you can modify the logic 

gr.addQuery('valid_to', gdt);

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

10 REPLIES 10

GBS
Tera Contributor

@Mark Manders I'm getting the past date articles but I want future articles that to exactly 2 months and not more than this