I have an aftersubmit that is grabbing the value o...
# suitescript
j
I have an aftersubmit that is grabbing the value of the salesrep and the billstate on create. It comes back as null. Is this normal behavior?
m
it should already be there at beforeSubmit, so no reason for it not to be there on aftersubmit. How are you grabbing it?
Or another question - it’s being sourced by NS, not being populated by a script/wf, right?
s
do both getValue and getString return null?
j
I am using a record.getValue('salesrep') and it is returning null on afterSubmit. The value is there. If I grab it after editing, I can get it. It seems to only return null when creating the record.
s
Are you using N/log to debug?
j
Yes
message has been deleted
You can see it logs when I delete one but when I create a new one, no rep.
I've paired down my script to the simplest form. It's literally just grabbing the context.type and sales rep and logging them.
This is happening on a customer record.
s
weird. not sure whats going on
j
I'm gonna go into sandbox and turn off all other scripts to confirm something else isn't interfering. NS has been driving me crazy this week. lol
s
As is tradition
m
Are you grabbing the oldRecord or newRecord?
j
newRecord
message has been deleted
m
I remember having an issue with this.
Where during create I needed to use the oldRecord. Can you try it just to be sure? I know it doesn't make sense
j
I'm willing to try anything. Let me do that.
Getting the trusty "cannot read property 'getValue' of null."
Gonna try turning off everything in sandbox now. I see some decade old workflows that are related to reps.
πŸ‘ 1
Yeah, none of that worked. I wonder if NetSuite natively sets the salesrep field in the aftersubmit stage since it is pulling from a sublist. Same with address related information. Looks like I gotta re-load the record up instead. Thanks for the suggestions.
s
does it have to be afterSubmit? Maybe try beforeSubmit?
j
I need aftersubmit in this case because I'm using https.post and I need the internalid
πŸ‘ 1
r
As a last resort, you can try creating a custom field that sources the value of the salesrep and see if you can get the value of the custom field via script.
m
Or search.lookupfield
j
Ooh, search is a good idea.
e
do you have salesteams?
j
Nah, just a rep.
d
in afterSubmit scripts, if it is an inline edit, the scriptContext.newRecord will only contain fields and field values of fields that were changed
if youre getting null, then you will have to do a search.lookupField to grab the value from the database, instead of grabbing value from the context
in non-inlineedit contexts, afterSubmit newRecords contain all fields as if you were doing a
record.load
or a lookup
πŸ™Œ 1
πŸ‘ 1
πŸ™ŒπŸ» 1
j
The search.lookupFields ended up being the route I had to take. Thanks to everyone for guidance. Hopefully I remember this next time it happens. πŸ˜„
πŸ‘ 1