I have a Client Script that runs on a Sales Order....
# suitescript
n
I have a Client Script that runs on a Sales Order. The script is telling me that Location is not visible despite it being visible.
Copy code
var locationField = record.getField({ fieldId: "location" });
log.debug("locationField", {
  locationField: locationField,
});
// Logs:
// {"id":"location","label":"","type":"text","isMandatory":false,"isDisabled":false,"isPopup":false,"isDisplay":false,"isVisible":false,"isReadOnly":false}}
How can I get the value of Location in a Client Script?
e
You retrieve values using
record.getValue()
, not
record.getField()
n
Understood, the problem is I call
record.getValue({ fieldId: "location" });
and it returns nothing.
e
Why do you need to call
getField()
?
n
I don't. I called
getField
because I don't understand why
getValue
does not return anything?
The real problem is
getValue
returns nothing, I was trying to diagnose why
e
Probably need to see more context in your script
Also, are your
log.debug()
statements showing up at all? I usually find it easier to use
console.log
in client scripts
n
log.debug
shows up but prints {} let me get you the rest of the script
e
How is
printPackingSlip
invoked? Are your other
getValue
calls working (e.g.
subsidiary
)?
n
subsidiary
works,
printPackingSlip
is invoked on a Sales Order Record Button Press, or rather a
UserEvent
script puts a button on the Sales Order during
beforeLoad
e
So this is running in VIEW mode then?
n
Correct
e
I don't think all values are present on the
CurrentRecord
instance in VIEW mode.
A quick example on an Employee in my account shows the
email
field coming back empty despite the fact there is clearly a value there
n
So thats why getField() / getValue() was turning up blank
e
and if I switch it to
subsidiary
, that does return the value
So you're likely going to need to
load
the record or do a
lookupFields
to get all the values you're interested in
n
ok, I'll refactor to use the N/Record module to load the record for real and try from there
Thanks for you help
1