Strange Client Includes Issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 05:13 PM
Hi! I have a Script Include, see below. I have a client script on a catalog form where I can type something in a text field and the text will be sent to the script include for querying. It shows "unhandled exception in GlidesAjax" error. But what's strange is, as you can see when I do gs.log and check the system log, I do see the searchTerm is expected.
If I hardcode the line below
searchTerm = this.getParameter('sysparm_searchTerm');
to
searchTerm = "test", it works. I'm so confused why the getParameter would give an error. I also copied the client script below.
Client Includes
var GetGrcEntitiesGlobal = Class.create();
GetGrcEntitiesGlobal.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getEntities: function(searchTerm) {
if (!searchTerm) {
searchTerm = this.getParameter('sysparm_searchTerm');
gs.log('GetGrcEntitiesGlobal called with searchTerm: ' + searchTerm);
}
var entities = [];
if (!searchTerm || searchTerm.length < 3) {
return global.JSON.stringify(entities);
}
var grcEntityGR = new GlideRecord('sn_grc_profile');
grcEntityGR.addActiveQuery();
grcEntityGR.addQuery('name', 'CONTAINS', searchTerm); // Filter based on the search term
grcEntityGR.query();
while (grcEntityGR.next()) {
entities.push({
sys_id: grcEntityGR.getValue('sys_id'),
name: grcEntityGR.getValue('name')
});
}
var result = global.JSON.stringify(entities);
return result;
},
type: 'GetGrcEntitiesGlobal'
});
Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue.length < 3) {
return;
}
var grcEntityField = g_form.getControl('ci_reference');
if (grcEntityField) {
var ga = new GlideAjax('global.GetGrcEntitiesGlobal');
ga.addParam('sysparm_name', 'getEntities');
var search_term = newValue.toString();
ga.addParam('sysparm_searchTerm', search_term);
ga.getXMLAnswer(function(response) {
var entities = JSON.parse(response);
grcEntityField.innerHTML = '';
g_form.addOption('ci_reference', '', '-- Select a Profile After Search --');
for (var i = 0; i < entities.length; i++) {
g_form.addOption('ci_reference', entities[i].sys_id, entities[i].name);
}
});
}
}