- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 12:24 PM
Hi All,
I have a requirement for a customer on a knowledge article, where when they choose a knowledge base on the article and that knowledge base has categories attached to it, to then make the category field on the knowledge article mandatory. Any ideas on how to do this?
Been stuck on this for a while, and would really appreciate the help.
Kind Regards,
Luke
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 12:42 PM
@Luke James You need to write onChange client script on knowledge article table then use GlideAjax on it to validate server side data.
Here is my sample script, which is working and i tested on my PDI.
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('validate_kb_cate');
ga.addParam('sysparm_name', 'getKb_cat');
ga.addParam('sysparm_cat', newValue);
ga.getXML(updateCampus);
}
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true')
g_form.setMandatory('kb_category', true);
else
g_form.setMandatory('kb_category', false);
}
Screenshot :
Script Include :
var validate_kb_cate = Class.create();
validate_kb_cate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKb_cat: function() {
var id = this.getParameter('sysparm_cat');
var kb = new GlideRecord('kb_category');
kb.addQuery("parent_id=" + id);
kb.query();
if (kb.hasNext())
return 'true';
else
return 'false'
},
type: 'validate_kb_cate'
});
Hope it will help you.
Let me know if you have any questions for me.
Thanks,
Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 12:42 PM
@Luke James You need to write onChange client script on knowledge article table then use GlideAjax on it to validate server side data.
Here is my sample script, which is working and i tested on my PDI.
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('validate_kb_cate');
ga.addParam('sysparm_name', 'getKb_cat');
ga.addParam('sysparm_cat', newValue);
ga.getXML(updateCampus);
}
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true')
g_form.setMandatory('kb_category', true);
else
g_form.setMandatory('kb_category', false);
}
Screenshot :
Script Include :
var validate_kb_cate = Class.create();
validate_kb_cate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKb_cat: function() {
var id = this.getParameter('sysparm_cat');
var kb = new GlideRecord('kb_category');
kb.addQuery("parent_id=" + id);
kb.query();
if (kb.hasNext())
return 'true';
else
return 'false'
},
type: 'validate_kb_cate'
});
Hope it will help you.
Let me know if you have any questions for me.
Thanks,
Harsh