- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:28 AM
Hi team
I need to populate date which is 1 year advance from current date on "valid to" field on knowledge article as well as I need to restrict user for selection of date should not more than year for valid to field
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 10:31 AM - edited 05-19-2024 10:32 AM
Hi there,
Have you tried using the validity field on knowledge base level?
When using this, when you create a new Knowledge article and select the Knowledge base, onChange the valid to is filled. Using my example, it would be today + 365 days.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 12:31 PM - edited 05-16-2024 12:56 PM
Hi @vamshi2 ,
You can create client script and call script include and set the valid to in KB article,
Here i didnt set the valid to field if you want uncomment the line number 15
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getTodaysDate');
ga.addParam('sysparm_name', 'getDate');
ga.getXML(getResponse);
}
function getResponse(response) {
var ans = response.responseXML.documentElement.getAttribute('answer');
alert('ans1' + ans);
//g_form.setValue('valid_to',ans); to set valid to field
if (g_form.getValue('valid_to') > ans) {
//checking if valid to selected is more than a year
alert('Valid to cannot be more than 1 year from now');
g_form.clearValue('valid_to');
}
}
Script Include:
var getTodaysDate = Class.create();
getTodaysDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDate: function(){
var todayDate = new GlideDate();
todayDate.addYears(1);
gs.info('today Date' + todayDate);
return todayDate;
},
type: 'getTodaysDate'
});
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 10:23 AM
The date format is different and it is not working as expected.. thank you
Pls suggest @swathisarang98 if anything code related to above requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 01:24 PM
@vamshi2 , checking for OOTB valid_to field right this should work i have checked in my pdi could you please share the screen shot of what you have tried ?
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 10:26 AM
Sorru=y for the delay
Yes above is working in PDI but in our instance it is not working
so i used Ui policy
valid to is relative after1 year from now
and