im trying to set this if it is null but doesnt see...
# suitescript
s
im trying to set this if it is null but doesnt seem to be working
Copy code
let phone =
        options.shipphone.length <= 0
          ? fulfillmentRecord.setValue({
              fieldId: "shipphone",
              value: "<tel:845-357-3600|845-357-3600>",
            })
          : options.shipphone;
      log.debug("phone", phone);
c
Copy code
options.shipphone.length <= 0
is not how to test for null
s
well what would you suggest as with NetSuite it could be null blank string or undefended
d
if using 2.1 script, you could do
!options?.shipphone
as first part of ternary expression also
Record.setValue
returns the Record instance itself, so "phone" will be assigned to fulfillmentRecord in that case, not sure if that's desired
s
i am trying to set it if nul/blank
d
yah should work for all those scenarios https://developer.mozilla.org/en-US/docs/Glossary/Falsy
s
it wouldnt work if its a blank string
d
!'' === true
-> true ? or you can also call
?.trim()
on it if you're meaning whitespace as blank
s
empty string is falsy. for the record, this sort of construct is like this with NFT
Copy code
fulfillmentRecord.shipphone = options.shipphone
s
Nft ?
s
This is such a common use case, if
options.shipphone
is undefined NFT automatically does nothing
in the broader sense though, I may be wrong but you might want to be using
shipingaddress
rather than mucking about with the deprecated individual body level fields
in which case, you'd write something like
fufillment.shippingaddress.addrphone = options.shipphone