anyone know why NetSuite insists on adding .0 to v...
# suitescript
j
anyone know why NetSuite insists on adding .0 to values when I’m trying to set them? I have a value, I’ve checked the typeof and it is
number
. The value is 20. When I try to use it in a setValue I get the error
You have entered an Invalid Field Value 20.0 for the following field
. If I turn it into a string (e.g. try to setValue with
myval + ''
it’s fine. I have no idea wtf NS is doing here or why.
this only seems to happen in a few places in SuiteScript
a
you said its a "number" the types in NS are "Decimal Number" and "Integer Number"... assuming you meant the NS data types, so is it an integer number?
i had something similar before and couldn't figure it out in any sane way so just ended up doing this... This is in my suitelet that's loading a previously stored WF id from a custom record and triggering it with some user supplied details
Copy code
let triggerObj = {
    recordType: recType,
    recordId: recId,
    workflowId: parseInt(workflowId,10),
 //why is this a thing?  wf ids were getting stored as xxx.0 and failing to trigger
but the fields types on my custom records are all text not number types
j
the field itself is of type
Integer
, the typeof of the JS variable is
number
with a value of 20. E.g. if I do
log.debug({title: 'myval type and value', details: typeof myval + ' ' + myval});
I get this:
a
yeah so i think NS just turns things into strings a lot... and at some point when its doing that and changing it back or something its adding the .0
j
I have had this issue previously with trying to have return parameters from WF Action scripts (I have to turn them into strings) but this has just started cropping up when trying to setValue for integers.
a
yeah I think maybe its WF related and NS wanting to use strings in its black box stuff... and then when it comes back it it tries to make them numbers again but sometimes does weird stuff instead
j
f*cking annoying
parseInt doesn’t even help I find
a
what?
j
at least not in my case
a
where are you doing it it? on the actual setfield itself?
but dont you already have a fix? if you do the
myval += ''
?
j
Yeah, but before I did that I was trying setValue({fieldId: ‘whatever’, value: parseInt(val)}) and that would fail. So now it seems I have to remember to add + ‘’ to all my setValues when it’s an integer. For <reasons>.
I dunno. At least it’s not only me.
e
Yeah, not just you. These little inconsistencies are always frustrating
1
b
you have to keep in mind that suitescript is ultimately calling java functions in its backend
java is pretty specific on its data types, its not dynamically types like javascript
so at some point it has to convert the javascript type into a java type
in particular, the javascript number data type will have to be converted into a java integer or float (or in your case, maybe a string)
thats going to be hard to get right, especially when you see how rounding starts working in edge cases
its why javascript strings are more consistent, its harder to mess that conversion up
a
that actually makes sense... I still hate NetSuite for being dumb though 😛
e
It makes sense, and I don't think any reasonable developer looks at NetSuite and says "Ah what a super easy system to build". But just because it's reasonable and difficult doesn't mean it can't also be frustrating for us. Situations like this are why I nearly always put a normalization layer between NetSuite's data and my logic.
💯 1