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

Brad Bowman
Kilo Patron
Kilo Patron

This error usually means the Script Include is inaccessible or not returning anything.  The Catalog Client Script is triggered onChange of company code, but since you are getting the error while loading, does company code have a default value or are you populating it onLoad?  If you inactivate this CCS do you still get the error?  Is the Script Include in the same scope as the Catalog Item?  I don't see anything wrong with the syntax on first glance, except maybe the sysparm_company_code - try using this instead

ga.addParam('sysparm_company_code', newValue);

Otherwise you can troubleshoot this by adding gs.info logs to the Script Include.  First on ccode to confirm this script is running and that the expect value is passed in from the client.  Then on inputs after assigning ccode, then response, etc. so you can see how far the script is getting.

Mani A
Tera Guru

try this

var response = dt.getDecisions('SYS ID of decision table', inputs);

for (var i = 0; i < response.length; i++)

{

var a = response[i].result_elements.u_choice_list;

    if (a) {

        arr.push(a);

       }

}

Hi Mani, 

 

Thanks for the response. I made the suggested changes in the script but still no luck, getting same error. Can you please suggest further.

Did you put logs in script include and client side once we received response

Please share the screenshot of logs