Update Valid date on knowledge article in a knowledge base

Sharon Williams
Tera Contributor

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

1 ACCEPTED SOLUTION

SudhirG
Kilo Sage

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.

SudhirGullapal_0-1684503045481.png

 

Please mark answer correct or helpful based on the impact.

Thanks,

Sudhir G

 

 

  

View solution in original post

3 REPLIES 3

SudhirG
Kilo Sage

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.

SudhirGullapal_0-1684503045481.png

 

Please mark answer correct or helpful based on the impact.

Thanks,

Sudhir G

 

 

  

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. 😎👍

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:

SudhirGullapal_0-1684755196707.png

Script include:

SudhirGullapal_1-1684755366789.png

 

Thanks,

Sudhir G