How to draft and validate date on valid to for knowledge article

vamshi2
Tera Contributor

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 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Have you tried using the validity field on knowledge base level?

 

MarkRoethof_0-1716139856673.png

 

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

LinkedIn

View solution in original post

7 REPLIES 7

swathisarang98
Giga Sage
Giga Sage

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

swathisarang98_2-1715887745539.png

 

 

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:

swathisarang98_3-1715887765065.png

 

 

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

 

 

 

The date format is different and it is not working as expected.. thank you 

 

Pls suggest @swathisarang98  if anything code related to above requirement

@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

Hi @swathisarang98 

 

 

Sorru=y for the delay

Yes above is working in PDI but in our instance it is not working 

 

so i used Ui policy 

vamshi2_0-1718299442103.png

valid to is relative after1 year from now 

 

and 

 

vamshi2_1-1718299523160.png