
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2016 07:30 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 09:44 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 09:44 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 10:43 AM
May I ask why does the script change based on the version of ServiceNow you are using.
And thank you again for your help.
Karen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 10:50 AM
Karen,
Starting from Fuji, Business rules come with a function created automatically. And you just need to add your code inside these functions. In eureka, there is no function initialization done by service now, so in your case you can declare your own function and call the function.
Note: In eureka, it also work if you just copy the code without creating any function like this
var gr= new GlideDateTime(current.sys_updated_on.getDisplayValue());
gr.addYears(1);
current.valid_to=gr.getDate();
But as a best practice you need to enclose your code in a function
Business Rules Best Practices - ServiceNow Wiki
ctomasi can give you more insight on this.
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 10:58 AM
Thank you again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2016 10:59 AM
All my thoughts are in the best practices docs. It represents years of my experience. 🙂