- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 10:02 AM
Hello Everyone
My below script is not populating the Data on Custom table
I want to populate the KB article number on custom table which contains the field reference to sc_cat_item
I have this relation available on the related list for every Catalog item through "sc_2_kb" relationship table
Script Include
var GetKnowledge = Class.create();
GetKnowledge.prototype.prototype = {
initialize: function() {},
getKBname: function(catalogItemSysId) {
var KBGR = new GlideRecord('sc_2_kb');
KBGR.addQuery('sc_cat_item', catalogItemSysId); // Reference field to Relation table
KBGR.query();
if (KBGR.next()) {
return KBGR.kb_knowledge; // Return the Knowledge
}
},
type: 'GetKnowledge'
};
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetKnowledge');
ga.addParam('sysparm_name', 'getKBname'); // Is Function in the script include
ga.addParam('sys_id', newValue);
ga.getXML(fetchData);
function fetchData(response) {
var getKB = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_knowledge_name', getKB);
}
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 11:50 AM
Your Script Include is not Client callable. You can check the box, but it will likely not change the formatting for an existing script, so here's what it should look like - also getting the parameter from the Client Script instead of passed in as an argument, which you would use when calling the Script Include from a UI Action, Business Rule, reference qualifier, etc. The Parameter name will probably work, but it would be best to rename it in both places to something consistent and not system/reserved like 'sysparm_sysid'. It's also best to always return something from a server script, to avoid browser console errors and aid in troubleshooting - to determine if the script even ran. This will get you closer.
var GetKnowledge = Class.create();
GetKnowledge.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKBname: function() {
var answer = 'false';
var catalogItemSysId = this.getParameter('sys_id')
var KBGR = new GlideRecord('sc_2_kb');
KBGR.addQuery('sc_cat_item', catalogItemSysId); // Reference field to Relation table
KBGR.query();
if (KBGR.next()) {
answer = KBGR.kb_knowledge; // Return the Knowledge
}
return answer;
},
type: 'GetKnowledge'
});
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 11:50 AM
Your Script Include is not Client callable. You can check the box, but it will likely not change the formatting for an existing script, so here's what it should look like - also getting the parameter from the Client Script instead of passed in as an argument, which you would use when calling the Script Include from a UI Action, Business Rule, reference qualifier, etc. The Parameter name will probably work, but it would be best to rename it in both places to something consistent and not system/reserved like 'sysparm_sysid'. It's also best to always return something from a server script, to avoid browser console errors and aid in troubleshooting - to determine if the script even ran. This will get you closer.
var GetKnowledge = Class.create();
GetKnowledge.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getKBname: function() {
var answer = 'false';
var catalogItemSysId = this.getParameter('sys_id')
var KBGR = new GlideRecord('sc_2_kb');
KBGR.addQuery('sc_cat_item', catalogItemSysId); // Reference field to Relation table
KBGR.query();
if (KBGR.next()) {
answer = KBGR.kb_knowledge; // Return the Knowledge
}
return answer;
},
type: 'GetKnowledge'
});
.