I want to increase the valid to date by 1 year

Cupcake
Mega Guru

I have a need by our customer to update the Valid To date in KB articles by 1 year every time that KB article is updated.

So it should be looking at the updated (sys_updated_on) field and making the Valid To date (valid_to) 1 year from that date.

Should this best be handled thru a business rule.

1 ACCEPTED SOLUTION

Karen,



  If you are on eureka, copy this script


setValidTo();


function setValidTo(){


var gr= new GlideDateTime(current.sys_updated_on.getDisplayValue());


gr.addYears(1);


current.valid_to=gr.getDate();


}



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

25 REPLIES 25

Chuck Tomasi
Tera Patron

Hi Karen,



A business rule would do this nicely.   See the addYears() method here.



GlideDateTime - ServiceNow Wiki


Thank you I will let you know how this works out for me.


Karen,



  As chuck said, write a before business rule


when: before insert and update


script: add this script inside the onBefore function


var gr= new GlideDateTime(current.sys_updated_on.getDisplayValue());


gr.addYears(1);


current.valid_to=gr.getDate();



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


So the script that you provided is not working as I intend it to.


find_real_file.png



Thanks,


Karen