- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 12:32 AM
KB articles is to set the Valid To date one year from the Published date. it's working fine now . should not allow more than one year from publish date . How can we restrict.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2017 04:24 AM
This is done, Please test and let me know.
Steps to test
1) Create a new article and submit it. (Do not enter Published date now)
2) Click on publish button to publish the article. This will populate the published date and Valid To dates (Valid to is Published date + 1 year)
3) Try to change valid to > 1 year, you will get an error and user cannot change it.
Business rules
Set Valid To Upon Publish
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var publishedDate = new GlideDateTime(current.published.getDisplayValue());
publishedDate.addYears(1);
current.valid_to = publishedDate.getDate();
})(current, previous);
Check Valid To
(function executeRule(current, previous /*null when async*/){
// Add your code here
var validDate = new GlideDateTime(current.valid_to.getDisplayValue());
var publishedDate = new GlideDateTime(current.published.getDisplayValue());
publishedDate.addYears(1);
if(validDate > publishedDate){
gs.addInfoMessage("You cannot select this date as Valid to");
current.valid_to = previous.valid_to;
current.setAbortAction(true);
}
})(current, previous);
If this has answered your question, please mark my response as correct answer.
Thanks
Please 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
‎03-23-2017 04:49 AM
Hi Hima,
Since I have answered your query, Can you please mark my response as correct answer?
https://community.servicenow.com/docs/DOC-5601
Thanks
Please 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
‎09-18-2019 07:13 AM
Hi-I was wondering if you could use the same logic but create a dynamic filter option and make the date a year from the date the published article is approved, rather than the date that publish is selected.
Currently, this is my code:
var gdt = new GlideDateTime(); gdt.addYearsUTC(1); gdt.getDisplayValue();
Thanks,
Heather
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 07:22 AM
Hi
I need to limit the KB Valid to date but so it is 12 months from the current date.
Please can you advise on this?
I had tried your business rule above for Published date + 12 months but found it was not working - is this because of the system timezone settings and display values (ours is dd/MMM/yyyy)?
Thank-you!
DS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 04:08 AM
Should we use both Business rules ?