so for `record.findSublistLineWithValue()` the "va...
# suitescript
d
so for
record.findSublistLineWithValue()
the "value" param takes types:
number | Date | string | array | boolean
as a sublist field (specifically a transaction line field in my case) can't be type multi-select, what kind of field would match a value of type
array
?
was trying to provide an array of values to see if any line had one of the values, but that didn't work Will just write a for loop to check, but wanted to know where you could ever provide an array to this method
s
I suspect passing an array to this would need to completely match the array?
I'm not sure however since I rarely use that - instead looping over the lines in a more functional /declarative style which reads better imho anyway.
👍 1
d
had a look at the client-side
doFindSublistLineWithValue
code and there's nothing specific to handle arrays. Interestingly it specifically accepts string/number matches (like
"1" == 1
) And also accepts where value is
true
or
false
, but the field value is "T" or "F"
s
NS's playing loose with number/string conversions have always irked me
d
yup.
it's mostly the inconsistency that annoys me
returned values are sometimes strings and sometimes numbers
s
_.find(so.item, i => _.includes(i.multiselectfield, 34))
Aye, we've been tempted to actually coerce things to the same type, but haven't gone that far. Instead we stop at just using TS types to describe how things should be, without going so far as to do type coercion in NFT
my little snippet above assumes
so
is a sales order and it's the
item
sublist you are trying to match a line from.
again, may have to match against "34" - I don't remember if that multiselect surfaces as an array of numbers or an array of strings...
facepalm 1
in any case, because I can generally use
_.find()
anywhere, I tend to stick to it and don't even think about
findSublistLineWithValue()
special API and I don't think anyone has found it to be faster than something like
_.find()
right, so possibly
_.find(so.item, i => _.includes(i.multiselectfield, '34'))
👍 1
d
"hey boss, so I need to book a sabbatical so I can pick up NFT"
you always make a good case for it
s
I find constructs like above are still concise but make it clear what the match predicate is, exactly. whereas 'findsublistLineWithValue()` makes that a bit of a mystery
a mystery which is indeed what started this entire thread 🙂
NFT is just applying plain idomatic javascript/typescript so there's actually much less to learn than someone coming at it from vanilla SuiteScript. However, I have found that folks struggle more if they've already been brainwashed with the native SS api for a long time.
a line like
_.find(so.item, i => _.includes(i.multiselectfield, '34'))
is understandable by anyone already familiar with lodash or similar collection libraries and modern JS.
i.e. that line has NO suitescript involved, and requires NO suitescript knowledge to understand.
anyway, I'll not soapbox further. I maintain it's a lot easier to find a developer that understands the code above than it is to find someone that knows about
fundSublistLineWithValue()
let alone knowing in addition the idiosyncrasies with that specific function.