- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 12:46 PM - edited 08-24-2023 12:47 PM
Hi All
I've a client script and Script include for validation of date 'Valid To' field on the Knowledge Article (kb_knowledge) table.
It is working perfectly fine when class of knowledge article is "KNOWLEDGE". However, it is not working when class of the knowledge article is different like "FAQ, HOW TO, WHAT IS, ERROR KNOWN ARTICLE".
Client script onchnage of 'valid To'
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == oldValue) {
return;
}
var valid_to = g_form.getValue('valid_to');
var ajax = new GlideAjax('KBValidToAjax');
ajax.addParam('sysparm_name', 'checkValidTo');
ajax.addParam('sysparm_validto', valid_to);
ajax.getXMLAnswer(function(answer) {debugger;
if (answer == "less than a year") {
alert('Valid to date cannot be less than a year from now.');
g_form.showFieldMsg('valid_to', 'Valid to date cannot be less than a year from now.', 'error');
g_form.setValue('valid_to', oldValue);
}
else if (answer == "more than five years") {
alert('Valid to date cannot be more than three years from now.');
g_form.showFieldMsg('valid_to', 'Valid to date cannot be more than three years from now.', 'error');
g_form.setValue('valid_to', oldValue);
}
});
}
Script Include
var KBValidToAjax = Class.create();
KBValidToAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkValidTo: function() {
var valid_to = this.getParameter('sysparm_validto');
var one_year = new GlideDate();
one_year.addYears(1);
var five_years = new GlideDate();
five_years.addYears(3);
if (valid_to < one_year) {
return "less than a year";
} else if (valid_to > five_years) {
return "more than five years";
}
// return 'valid_to: '+ valid_to +' one_year: ' + one_year;
},
type: 'KBValidToAjax'
});
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:11 PM
Hi @MR1
have you ticked the checkbox "Inherited" on your Client Script? If not the Client Script will not be executed on child tables:
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:11 PM
Hi @MR1
have you ticked the checkbox "Inherited" on your Client Script? If not the Client Script will not be executed on child tables:
Maik