Hi! I have an issue with following CS, fieldChange...
# suitescript
s
Hi! I have an issue with following CS, fieldChange, code. It works perfectly fine in Firefox but not in Chrome. In Chrome "currentRecord.getCurrentSublistValue" is null when selecting the Item. However, if I select another item on the same line it works. Any ideas how to make it work also in Chrome? Is Chrome executing in some other way, that I need to adress? function fieldChanged(scriptContext) { // console.log('Calling function: ' + arguments.callee.name + ', scriptContext: ' + JSON.stringify(scriptContext)); try { if (scriptContext.sublistId === 'item' && scriptContext.fieldId === 'item' || scriptContext.sublistId === 'item' && scriptContext.fieldId === 'quantity') { var quantity = currentRecord.getCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', line: scriptContext.line }); currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'custcol_sk_antal_hl', value: quantity, line: scriptContext.line, }); } } catch (e) { log.error({ title: arguments.callee.name, details: JSON.stringify(e) }); } }
d
@stepos have you tired removing the line parameter that is not needed while using the getCurrentSublistValue
s
@DATTA thanks for reply! Just tried that, but with the same result. It seems to be a different behaviour in Chrome!
d
did you tried this clearing cookies and cache
s
No, but will do that. Hope it's that easy ... 🙂
Didn't work either unfortunately. I get the same issue from all other users as well.
d
try this add one validation if value present then set the value
if not then don't do anything
s
No. The issue is actually getting it. At first selection of the item (on each line), I get null in Quantity. If I reselect an item on the same row I get a value, which is also set correctly.
d
ohh
s
Executing in Firefox I get the value and can set it. So, different behaviours in the respective browsers.
d
its actually some strange behaviour
s
Don't know if this is related, but this example code is executed differently in Chrome vs Firefox. https://stackoverflow.com/questions/50098194/firefox-vs-chrome-javascript-interpreter-differences-and-similarities
Very strange ... it's really a bit of simple code!
d
I get it when at the first time you are selecting the item at that time quantity is null it will take some time to populate default quantity as 1
can you try post sourcing
s
Yes, that is an idea of course. Still strange though that Firefox can make it. But it's perhaps faster!
Post sourcing works fine. Thanks for your help!
d
you're welcome
s
currenetRecord
should not be defined unless you have it saved to a global variable. I think you want to use
scriptContext.currentRecord or something
s
@Shawn Talbert yes. I have "var currentRecord = scriptContext.currentRecord;" defined, but it didn't show in code above! Thanks.
s
It seems that chrome and (chromium) Edge seem to dominate my world these days. Guess I should be happy I'm not supporting FireFox?
s
In this case Firefox works great, but Chrome does not, so I don't know 🙂
s
oh, sorry I read it backwards
g
Copy code
(scriptContext.sublistId === 'item' && scriptContext.fieldId === 'item' || scriptContext.sublistId === 'item' && scriptContext.fieldId === 'quantity')
FYI, i don’t think this means what you think it means.
s
@Gerald Gillespie what do you mean?
g