catalogitem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 10:57 PM - edited 04-25-2024 11:26 PM
Hello, ive a service catalog page and some items to order, once user user click on the submit, it shows the error as given in the question. i check the console the following error shows up.
[SCRIPT:EXEC] Error while running Client Script "total amount for ID's": SyntaxError: Unexpected end of JSON input
[SCRIPT:EXEC] Error while running Client Script "total amount for invoice to apply": SyntaxError: Unexpected end of JSON input
How to fix it?
"There is a java script error in your browser console"
error
The catalog client script use is :
function onSubmit() {
if (g_form.getValue("u_request_type") == "Inventory Adjustment") {
var multiRowVariableSet = JSON.parse(g_form.getValue('invoice_s_to_apply_to'));
var tot = 0.00;
for (var i = 0; i < multiRowVariableSet.length; i++) {
var amount_two = +multiRowVariableSet[i].amount_two;
if (!isNaN(amount_two)) {
tot += amount_two;
} else {
console.error("Invalid amount detected at index " + i + ". Skipping calculation.");
}
}
g_form.setValue("total_invoice_amount", tot.toFixed(2));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 06:29 AM
I don't know that this would cause that error, but you have an errant + character in this line
var amount_two = +multiRowVariableSet[i].amount_two;
I have seen an error parsing the value when a MRVS is empty as the native UI returns [] as the value, so I usually break it down like this:
var multiRowVariableSet = g_form.getValue('invoice_s_to_apply_to');
if (multiRowVariableSet.length > 2) {
var obj = JSON.parse(multiRowVariableSet);
for (var i=0; i<obj.length; i++) {
...
Otherwise, try alerting on the value of (unparsed) multiRowVariableSet - does it look well-formatted, or does it contain a special character that could be throwing off the parsing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 06:59 AM
try the code shared by Brad and share the feedback
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader