i think i'm getting close :sweat_smile: a bit puz...
# suitescript
k
i think i'm getting close 😅 a bit puzzled by this one though:
Copy code
const rec = record.create({
  type: record.Type.SALES_ORDER,
  isDynamic: false
});
...
const customerId = 268554; // actually the value returned by a search
rec.setValue('entity', customerId);
gives an error:
..."name":"INVALID_KEY_OR_REF","message":"Invalid entity reference key 268554."...
i can see in the UI that a customer exists with this id is this some kind of incorrect permissions? (i don't think so - i basically copied celigo's permissions for starters) is
entity
the wrong field? do i have to use dynamic mode for some reason?
e
Is the customer inactive?
k
i don't think so - customer was created via the api, so it's whatever the default is. inspecting the customer record with "netsuite field explorer" extension, i see
isinactive: "F"
e
only other thing I can thin k of is that the role you're using doesn't have access to the subsidiary of the customer
k
is there a way to get an actual failure reason? (e.g. have it tell me access was denied, if it's a permission problem)
just being able to tell the difference between a code problem and a permission problem will cut the surface area significantly
e
Apart from entering an enhancement request that will likely never get done, no
😭 1
k
makes me feel better about spending whole days on creating useful error messages lol.
maybe that's a mentality i inherited from stripe 🙂
i think i figured it out though
i've been using the
@hitc/netsuite-types
repo to help, but i'm not happy with it - seems to be either out of date or mistaken sometimes. this is one instance of such: it says that record.save() returns a number - but it returns a string
so i was calling setText on the entity field (which is a select - can accept [presumably] an internal id [a number] or a string [a name that resolves to an id])
with the string value of the id 😅
and of course typescript didn't help me because the types are wrong
... it's not that one, but maybe
rec.id
that's wrong. something that i'm expecting to be a number is a string, at any rate
e
It does return a number, but NS has a few inconsistencies when it comes to internal ids. You'll expect a number, and you may get a number, a string, or a float
k
a float? 😱
e
it happens 😕
k
what does that even mean
customer id = Infinity 😂
e
var recId = myRec.save() might return 123481.0
k
oh
so it's just an integer as a floating point value you mean?
as opposed to an actual fractional number
(js makes no distinction, but it'd be weird for it to stringify as .0 unless you use toFixed)
s
@hitc/netsuite-types is the most accurate typings available for NetSuite. The inconsistency of NS to use numbers and strings for ids makes me still use
==
over
===
in many cases
one notiable thing is search results - all columns (search outputs) tend to be strings as a general rule, regardless of what the related record field type is
k
that makes some amount of sense
in this case, i have a record and i'm calling
.id
on that record. its type is
number
, not
number|string
or whatever, so it faked me out 😅
i've dealt with it in the general case though now
when i set a field that i expect to be an internalid, it ensures it is using setValue with a number
once i adjusted my mental model from "a programming API" to "a browser-based UI scripting API", a lot of things made more sense 😅