How to fix the error "There is a JavaScript error in your browser console".

Community Alums
Not applicable

I'm Populating MRVS value if the MRVS value is empty it shows : There is a JavaScript error in your browser console

In Console : Unhandled exception in GlideAjax

 

How can we fix this error?

The client script I have written is below-

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('service_provider_revenue_coa');
g_form.clearValue('department_credit_coa');
g_form.clearValue('order_price');
return;
}
try {

var ga = new GlideAjax('WOSYSAjax');
ga.addParam('sysparm_name', 'getCreditMemoCOA');
ga.addParam('sysparm_order', newValue);
ga.getXMLAnswer(response);
} catch (e) {
alert("Failed to get EACS Roles: " + e);
return ;
}


function response(res) {
var answer = JSON.parse(res);
var charge = answer.chargeCOA;
var revenue = answer.revenueCOA;
var price = answer.price;
console.log(answer);
console.log(revenue);
console.log(charge);
console.log(price);
if (revenue != '') {
g_form.setValue('service_provider_revenue_coa', revenue);
}
if (charge != '') {
g_form.setValue('department_credit_coa', charge);
}
if (price != '') {
g_form.setValue('order_price', price);
}
}

}

 

 

The  script Include I have written is below-

getCreditMemoCOA: function() {
var orderID = this.getParameter('sysparm_order');
var result = {
"revenueCOA": this.getCreditMemoRevenueCOA(orderID),
"chargeCOA": this.getCreditMemoChargeCOA(orderID),
"price": this.getOrderPrice(orderID),
};
return JSON.stringify(result);
},

getCreditMemoRevenueCOA: function(orderID) {
var result = '';
var grOrder = new GlideRecord('x_unocr_work_order');
if (grOrder.get(orderID)) {
result = grOrder.variables.revenue_coa_code + '';
var par = JSON.parse(result);
par[0].rv_percent = '';
var string = JSON.stringify(par);
gs.info(string);
string = string.replaceAll('rv_', 'spcc_');
string = string.replaceAll('percent', 'amount');
string = string.replaceAll('coa_code_valid', 'valid_coa_code');
gs.info(string);
return string;
}
return string;
},

getCreditMemoChargeCOA: function(orderID) {
var result = '';
var grOrder = new GlideRecord('x_unocr_work_order');
if (grOrder.get(orderID)) {
result = grOrder.variables.coa_code + '';
var par = JSON.parse(result);
par[0].percent = '';
var string = JSON.stringify(par);
gs.info(string);
string = string.replaceAll('vs_', 'dcc_');
string = string.replaceAll('_otf', '');
string = string.replaceAll('entities', 'entity');
string = string.replaceAll('cost_center', 'flex_1');
string = string.replaceAll('project_code', 'flex_2');
string = string.replaceAll('percent', 'dcc_amount');
string = string.replaceAll('valid_coa_code', 'dcc_valid_coa_code');
return string;
}
return string;
},

getOrderPrice: function(orderID) {
var price = {};
var grOrder = new GlideRecord('x_unocr_work_order');
if (grOrder.get(orderID)) {
price = grOrder.getDisplayValue('price');
}
return price;
},

 

 

1 ACCEPTED SOLUTION

shyamkumar VK
Kilo Patron

Can you please update your client side code as below and retest?

 

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue == '') {
    g_form.clearValue('service_provider_revenue_coa');
    g_form.clearValue('department_credit_coa');
    g_form.clearValue('order_price');
    return;
  }
  try {
    var ga = new GlideAjax('WOSYSAjax');
    ga.addParam('sysparm_name', 'getCreditMemoCOA');
    ga.addParam('sysparm_order', newValue);
    ga.getXML(response);
  } catch (e) {
    alert("Failed to get EACS Roles: " + e);
    return ;
  }

  function response(res) {
    var answer = JSON.parse(res.responseXML.documentElement.textContent);
    var charge = answer.chargeCOA;
    var revenue = answer.revenueCOA;
    var price = answer.price;
    console.log(answer);
    console.log(revenue);
    console.log(charge);
    console.log(price);
    if (revenue != '') {
      g_form.setValue('service_provider_revenue_coa', revenue);
    }
    if (charge != '') {
      g_form.setValue('department_credit_coa', charge);
    }
    if (price != '') {
      g_form.setValue('order_price', price);
    }
  }
}

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

View solution in original post

2 REPLIES 2

shyamkumar VK
Kilo Patron

Can you please update your client side code as below and retest?

 

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue == '') {
    g_form.clearValue('service_provider_revenue_coa');
    g_form.clearValue('department_credit_coa');
    g_form.clearValue('order_price');
    return;
  }
  try {
    var ga = new GlideAjax('WOSYSAjax');
    ga.addParam('sysparm_name', 'getCreditMemoCOA');
    ga.addParam('sysparm_order', newValue);
    ga.getXML(response);
  } catch (e) {
    alert("Failed to get EACS Roles: " + e);
    return ;
  }

  function response(res) {
    var answer = JSON.parse(res.responseXML.documentElement.textContent);
    var charge = answer.chargeCOA;
    var revenue = answer.revenueCOA;
    var price = answer.price;
    console.log(answer);
    console.log(revenue);
    console.log(charge);
    console.log(price);
    if (revenue != '') {
      g_form.setValue('service_provider_revenue_coa', revenue);
    }
    if (charge != '') {
      g_form.setValue('department_credit_coa', charge);
    }
    if (price != '') {
      g_form.setValue('order_price', price);
    }
  }
}

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Community Alums
Not applicable

Thanks