Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Need help with the script

jatin24j242424
Tera Contributor

 

Hi All, 

 

I need assistance in fixing the error that I am getting on Service Portal while the catalog item loads, error ' there is a javascript error in the browser console'. 

 

I have created the decision table, and using the below scripts (catalog client script & Script Include). Script tested in Background-Script option and running fine , giving the desired outputs, but when pasting in the client callable Script Include (for all applications) its not working, seems i am doing mistake with the syntax part.  Request to please validate the scripts & assistance in fixing it - 

 

Script Include - 

var GetChoicesFromDT = Class.create();
GetChoicesFromDT.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getChoices: function() {


var ccode = this.getParameter('sysparm_company_code');
var dt = new sn_dt.DecisionTableAPI();
var inputs = new Object();
inputs['u_company'] = ccode;
// gs.info('choiceArr');
var arr = [];

var response = dt.getDecisions('SYS ID of decision table', inputs);
for (var i = 0; i < 10; i++) {
var a = response[i].result_elements.u_choice_list;
arr.push(a);
// gs.print(a);
}
return arr.toString();


},

type: 'GetChoicesFromDT'
});

 

Catalog Client Script - (Onchange on company code)

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('GetChoicesFromDT');

ga.addParam('sysparm_name', 'getChoices');
ga.addParam('sysparm_company_code', newValue.toString());

ga.getXMLAnswer(returncode);

function returncode(response) {

// var answer = response.responseXML.documentElement.getAttribute('answer');
var answer = response;
alert(answer);
var arr = answer.split(",");
/* for (var i = 0; i < arr.length; i++) {

// var variableName = answer[i].trim();
g_form.setVisible(arr[i], true);
} */

}
}

 

 

 

6 REPLIES 6

In logs, error showing is 'Unknown field in table core_company'. Till var arr = [];, its working fine in script include. Pls suggest further. 

What are u getting in response and inside for loop and also data in array ?

Please make sure to use correct input fieldnames of decision table in script

 

Share screenshot or your code once with logs