Outdated state and Valid To field knowledge

alexm1
Tera Contributor

Hello,

I'm trying to set the valid_to date on the knowledge form based on the workflow status of the article. For example if workflow status is review date is set to current day. 

I'm doing this from a business rule and all conditions work great except for when workflow state is Outdated. Nothing happens  when workflow state changes to Outdated. We are using versioning. 

How conditions work:

If state is Draft  - valid_to is populated with a fixed date

if state is review - valid_to is populated with  current date

if state is published - valid_to is populated with current date + 1 year

If state is pending retirement - valid_to is populated with current date

if state is retired - valid_to is populated with current date

if state is outdated - valid_to should be populated with the current date but it's not, date stays unchanged. 

Need some help to change this date to current date when workflow status changes to Outdated.

Thanks,

Alex

 

 

9 REPLIES 9

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you share code or a screenshot of what you're using to set the valid to date now?

Hi Brad,

I created a business rule.

find_real_file.png

 

var gdt = new GlideDateTime();
var kb = current.kb_knowledge_base;

var time = new GlideDateTime();
time.addYearsUTC(1);
time.setMonthUTC(1);
time.setDayOfMonthUTC(1);

if(current.workflow_state == 'published' && kb == 'fbee3e51db866f0083429532ca96192a'){
gdt.addYearsUTC(1);
current.valid_to = gdt.getDate();

else if(current.workflow_state == 'review' && kb == 'fbee3e51db866f0083429532ca96192a' ||current.workflow_state == 'outdated' && kb == 'fbee3e51db866f0083429532ca96192a'){ 
current.valid_to = gdt.getDate();

} else if(current.workflow_state == 'draft' && kb == 'fbee3e51db866f0083429532ca96192a'){
current.valid_to = time.getDate();

 

Code could have been written better but for know it does its job except for the Outdated state.

Thanks,

Alex

I see there are some syntax errors in the script.

Here is the updated one

var gdt = new GlideDateTime();
var kb = current.kb_knowledge_base;


var time = new GlideDateTime();
time.addYearsUTC(1);
time.setMonthUTC(1);
time.setDayOfMonthUTC(1);


if(current.workflow_state == 'published' && kb == 'fbee3e51db866f0083429532ca96192a'){
	gdt.addYearsUTC(1);
	current.valid_to = gdt.getDate();
}

else if( (current.workflow_state == 'review' && kb == 'fbee3e51db866f0083429532ca96192a') || (current.workflow_state == 'outdated' && kb == 'fbee3e51db866f0083429532ca96192a')){
	current.valid_to = time.getDate();
	
	
} else if(current.workflow_state == 'draft' && kb == 'fbee3e51db866f0083429532ca96192a'){
	current.valid_to = time.getDate();
}

Brad Tilton
ServiceNow Employee
ServiceNow Employee

This updated script from dvp is better, but if you're saying that it worked when the workflow state is review, but not outdated then I'm not sure why that would be the case.

Could you retest to make sure review works and outdated doesn't, and then check the value of the outdated option?

I'm not sure if you have this in your conditions somewhere, but I would also only run this when the workflow_state changes other wise this is going to run on just about every update.