- 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
12-16-2024 05:00 AM
@Juhi Poddar how to modify the script if I want the articles which will expire in 1months and also in 2months
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 05:33 AM
Hello @GBS
To do minimum changes in your previous code, try this while making a query:
gr.addQuery('valid_to', gdt);
gr.addQuery('valid_to', gdt.addMonths(-1));
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
12-16-2024 07:10 AM - edited 12-16-2024 07:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 07:58 AM
Hello @GBS
You are most welcome!
Glad to help you resolve your query.
If the solution worked for you, can you please hit like and mark it as an accepted solution.
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:17 AM
You are adding an encoded query without a query in your script. That doesn't do much.
Can you check this (it worked on my instance):
var kbArticle = new GlideRecord('kb_knowledge');
kbArticle.addEncodedQuery('workflow_state=published^kb_knowledge_base.title=HR^valid_toRELATIVELT@month@ahead@2');
kbArticle.query();
if (kbArticle.hasNext()) {
gs.print('Articles expiring after the end of this month:');
while (kbArticle.next()) {
var kbName = kbArticle.kb_knowledge_base.getDisplayValue();
gs.print('Article Number: ' + kbArticle.number);
gs.print('Title: ' + kbArticle.short_description);
gs.print('Knowledge Base: ' + kbName);
gs.print('Expiration Date: ' + kbArticle.valid_to);
gs.print('----------------------------------');
}
} else {
gs.print('No articles found expiring after the end of this month.');
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark