I have a sublist which has 3 columns (name, percen...
# suitescript
b
I have a sublist which has 3 columns (name, percent, price), a field named "Total" and a field named "Total with Taxes" Name is string, that price should be total * percent / 100 So if sublist has 3 rows Total with Taxes should be some of Total and that 3 Prices. However when I try to set Price using ValidatedLine or SublistChanged it throws me an error saying "RangeError Maximum call stack size exceeded". It looks like because of loop I think. I tried to use "ignoreFieldChange" but it didn't work Could anyone help on this please?
s
I don’t think a large loop would affect the call stack (but I’m not sure how the JS to JVM code is transpiled), but it’s not uncommon to have a SuiteScript that can loop on a few thousand search results just fine. More likely, you have some deep recursion. ignoreFieldChange is just a setting on a SuiteScript API call and will have no impact on the call stack. Anyway, no code was shared, so there’s really no way anyone here can know what the issue is. You’ll need to provide the relevant part of the script at least.
b
Yes I mean to say deep recursion
s
if you can't easily prevent your function from being called by NS many times, you can try using
_.debounce()
n
I would say something is wrong with your script. It's getting stuck in a loop of validateField/ValidateLine and that's why throwing the range error. Share your code.
s
I can’t really think of a reason why you’d need a recursive (and especially not a deeply recursive) function in most SuiteScripts, though possibly a third party library might make use of them. Usually you would use iterators & callback functions or a loop (do, while, for) to go through each line. Again, you’d have to provide the code, as there’s no way to troubleshoot based on on the error message alone.
s
the recursion is not likely end-user code - more like NS calling the entrypoint repeatedly. If that happens when it seems it shouldn't, _.debounce() is an easy get-out-of-jail-free card.
b
nothing that you shared looks like it could cause recursion, which probably means the problem is elsewhere
the logic within your for loop doesnt actually commit anything
so the validateLine shouldnt come into play
that means that either
Copy code
form.selectLine({
  sublistId: "custpage_fee_lines",
  line: i,
});
is triggering a lineInit
or
Copy code
form.setCurrentSublistValue({
  sublistId: "custpage_fee_lines",
  fieldId: "custcol_fee_calced",
  line: i,
  value: rate * Amount * Price,
});
is triggering a validateField or fieldChanged (and also has a badly named fieldId)
or the more unlikely
Copy code
form.setValue("custpage_price_per_gallon", total / Amount);
form.setValue("custpage_total_with_tax", total);
are triggering a triggering a validateField or fieldChanged