There is a JavaScript error on Browser console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 10:53 AM
Hello,
I'm getting a browser console JavaScript error on my Record Producer from the portal side.
Here is my code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var index = "1";
var spendPlan = "spend_plan_" + index;
var amount = "original_amount_" + index;
var adjAmount = "adjusted_amount_" + index;
var total = 0.0;
g_form.setDisplay('total_adjusted_amount', false);
g_form.setValue('total_adjusted_amount', '');
//clear and hide all fields
for (var i = 1; i < 11; i++) {
index = (i).toString();
spendPlan = "spend_plan_" + index;
amount = "original_amount_" + index;
adjAmount = "adjusted_amount_" + index;
g_form.setDisplay(spendPlan, false);
g_form.setValue(spendPlan, '');
g_form.setDisplay(amount, false);
g_form.setValue(amount, '');
g_form.setDisplay(adjAmount, false);
g_form.setValue(adjAmount, '');
}
if (!isLoading && newValue != oldValue) {
var ga = new GlideAjax('x_g_duas_abm.DCSA_ABMUtils');
ga.addParam('sysparm_name', 'getRequestDetails');
ga.addParam('sysparm_req_id', g_form.getValue('funding_request'));
ga.getXML(gaCallBack);
}
function gaCallBack(response) {
//Grabs answer from GlideAjax call
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
for (var i = 0; i < answer.spendPlan.length; i++) {
index = (i+1).toString();
spendPlan = "spend_plan_" + index;
amount = "original_amount_" + index;
adjAmount = "adjusted_amount_" + index;
total += parseFloat(answer.amount[i]);
g_form.setDisplay(spendPlan, true);
g_form.setValue(spendPlan, answer.spendPlan[i]);
g_form.setDisplay(amount, true);
g_form.setValue(amount, formatNumber(parseFloat(answer.amount[i])));
g_form.setDisplay(adjAmount, true);
g_form.setValue(adjAmount, formatNumber(parseFloat(answer.amount[i])));
}
g_form.setDisplay('total_adjusted_amount', true);
g_form.setValue('total_adjusted_amount', formatNumber(total));
}
}
function formatNumber(num) {
return '$' + num.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
}
Can anyone direct me as to what I have done wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:36 AM
Check the console to see if there are any more details on the error. Usually this is caused by the GlideAjax call - there is not cross-scope or a role to access to the Script Include, or something that causes it to either not run or not return anything to the client. Add a gs.info log to the SI to confirm it is running, then whatever key points along the way to see if it has a value to return to the client, then alert on the client script to confirm that value is received.
Make sure the SI is Accessible from All Application scopes
Check the ACL associated with the SI, and make sure it has the public role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:42 AM
Thank you. I'll test this out.