- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:01 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:12 AM
Hello @GBS
Please try the below script:
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('workflow_state', 'published');
gr.addQuery('kb_knowledge_base.title', 'HR');
// Calculate the expiration date (2 months from now)
var gdt = new GlideDateTime();
gdt.addMonths(2);
// Use the calculated date for filtering articles expiring within 2 months
gr.addQuery('valid_to', '<=', gdt);
// Execute the query
gr.query();
if (gr.hasNext()) {
gs.print('Articles expiring within the next two months:');
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 within the next two months.');
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:25 AM
@Juhi Poddar I have changed
gr.addQuery('valid_to', '>=', gdt); to get the future dates but it is also showing the articles valid to is more that 2 months but I want exact 2 months
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:51 AM
@Juhi Poddar it worked. Thank you!