BrainFreeze: How do I get a record value in an Af...
# suitescript
d
BrainFreeze: How do I get a record value in an AfterSubmit - DELETE - XEDIT ? (I cannot do a lookField right?)
n
scriptContext.oldRecord and scriptContext.newRecord
You will only get oldRecord in Delete
d
Sorry @NickSuite, those are not accurate statements
n
Copy code
function afterSubmit(scriptContext) {
    var soRec = scriptContext.newRecord;
    var soRecOld = scriptContext.oldRecord;
}
It should be like this
d
When a record is XEDIT'ed, you only get the fields that were edited
So, you're forced to load the record (or use lookupFields) in an XEDIT situation
But, my corner case is a DELETE with xedit, so I cannot load the record any more
n
When a record is XEDIT'ed, you only get the fields that were edited, oh yes. I just checked the doc
How can you delete with XEDIT?
d
In NetSuite, if you list out a set of records and turn on inline editing, you can delete
s
the
id
property isn't there?
d
It is, but you cannot load the record (as it was just deleted) in the aftersubmit
s
can you move to beforeSubmit()?
d
Its an option ... but a pretty be lift
I'll give the afterSubmit another 30mins of effort
I was thinking about capturing the field value in the beforeSubmit (into cache) and use it in the aftersubmit
s
that would probably work but it seems to use beforeSubmit() is more fitting - that event has all the data you need and avoids likely additional performance hit of afterSubmit()?
I only use afterSubmit() if unavoidable due to the load/lookup/whatever performance penalty
d
Ya, its a crazy use case where I need to cascade the delete to a bunch of related records
I don't (can't) want to get in the way of NetSuite's delete operation in the BeforeSubmit
I think this little cache trick will do just nicely
Yep, beautiful
s
hopefully your design can tolerate if for some reason that cache is unset by the time aftersubmit runs?
I would expect that to be highly unlikely, but NS makes no guarantees about lifetime of the cache IIRC?