- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 05:22 AM
I have a knowledge base (Operation Support) that contains knowledge articles where I need to update the 'Valid to' date field to 1/1/2100. I would like help with creating a background script or fix script for this.
I also need to ensure that when a new KB is created for in this knowledge base, it defaults to a 'Valid to' date of 1/1/2100.
Thanks...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 06:32 AM
Hi @Sharon Williams ,
You can run below fix script. Add sys_id of the required knowledge base in encoded query.
var valid_to = new GlideDate();
valid_to.setValue('2200-01-01'); //Add required date.
var grKb = new GlideRecord('kb_knowledge');
grKb.addEncodedQuery('workflow_state=published^kb_knowledge_base=sys_id_of_knowledge_base');
grKb.query();
while(grKb.next()){
// prevents business rules executions.
grKb.setWorkflow(false);
// prevents updating updated, updated by fields on the record.
grKb.autoSysFields(false);
grKb.valid_to = valid_to;
grKb.update();
}
For default valid to date on the knowledge base articles configure below on the knowledge base record.
Please mark answer correct or helpful based on the impact.
Thanks,
Sudhir G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 06:32 AM
Hi @Sharon Williams ,
You can run below fix script. Add sys_id of the required knowledge base in encoded query.
var valid_to = new GlideDate();
valid_to.setValue('2200-01-01'); //Add required date.
var grKb = new GlideRecord('kb_knowledge');
grKb.addEncodedQuery('workflow_state=published^kb_knowledge_base=sys_id_of_knowledge_base');
grKb.query();
while(grKb.next()){
// prevents business rules executions.
grKb.setWorkflow(false);
// prevents updating updated, updated by fields on the record.
grKb.autoSysFields(false);
grKb.valid_to = valid_to;
grKb.update();
}
For default valid to date on the knowledge base articles configure below on the knowledge base record.
Please mark answer correct or helpful based on the impact.
Thanks,
Sudhir G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 08:31 AM
Thank you Sudhir! I found that if the Article Validity field is null in the Knowledge Base all new KBs created default with the Valid to field set to 01-01-2100. So no need to Set default knowledge values - Valid to field. There may be a business rule or something running on the back end to make this happen. 😎👍
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 04:36 AM
Hi @Sharon Williams ,
Yes default valid to date is configured in the 'valid_to' field dictionary configuration as a default value which in turn calls a script include to get the default date if 'Article validity' is defined else sets the default value.
Dictionary:
Script include:
Thanks,
Sudhir G