How can I over write the "Valid to" in KB article?

JLeong
Mega Sage

Hi Guys,

I need to overwrite the default Valid to date in the KB article. OOB, when you check out an article, automatically it sets it to 2100-01-01.

I need to keep the current Valid to date if it's greater than today's date and not update it to 2100-01-01.

find_real_file.png

 

Thank you in advance.

Regards,

Jocelyn

 

 

1 ACCEPTED SOLUTION

Andrea Elms
Kilo Guru

Hello,

You can also set the Article Validity on the Knowledge for a certain amount of days after publishing.

find_real_file.png

View solution in original post

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hello,

Can you give more information?

When creating an article the default date is 01/01/2100.

You said:
"I need to keep the current Valid to date if it's greater than today's date"...but this default date is only set to that 2100 year, etc. on new records, otherwise you change it yourself, save, and then that's it...it's changed. But again, the default date is greater than today's date...

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

Thanks for replying to my email. I updated the Checkout UI action. I added the lines in red.

If the valid to date is in the future do not update to 2100-01-01

// TODO Move the messages to messages table
var gd = new GlideDate();
var toDate = (gd.getDisplayValueInternal());

var recordClass = current.sys_class_name;
var previous_valid_to = current.getDisplayValue("valid_to");
var newRecord = new KBVersioning().checkout(current);
if (newRecord) {
if (recordClass == 'kb_knowledge_block')
gs.addInfoMessage(gs.getMessage("A new version of the block is created for revision."));
else
gs.addInfoMessage(gs.getMessage("A new version of the article is created for revision."));


var current_valid_to = newRecord.getDisplayValue("valid_to");

if (previous_valid_to > toDate) {
gs.log('The current valid date is in the future, do not update - ' + previous_valid_to);
current_valid_to = previous_valid_to;
current.valid_to = previous_valid_to;
newRecord.valid_to = previous_valid_to;
}


if (previous_valid_to != current_valid_to) {
if (gs.nil(previous_valid_to))
gs.addInfoMessage(gs.getMessage("Valid to has been changed to {0}.", current_valid_to));
else
gs.addInfoMessage(gs.getMessage("Valid to has been changed from {0} to {1}.", [previous_valid_to, current_valid_to]));
}

action.setRedirectURL(newRecord);
} else
gs.addErrorMessage(gs.getMessage("You cannot checkout this article as it is already checked out."));

Prateek kumar
Mega Sage

Please take a look at below:

https://community.servicenow.com/community?id=community_question&sys_id=8bf50761db1cdbc01dcaf3231f96...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek,

Thanks for your reply. Dynamic Default Value is not working. It still goes back to 2100-01-01.

Regards,

Jocelyn