Hello, is there a reason why an oldrecord call wou...
# suitescript
p
Hello, is there a reason why an oldrecord call would not get the field value that was changed? I am tracking it in the logs and it is returning the same value as the newrecord call
b
id double check that it isnt something like the record being saved twice
p
do you mean like multiple aftersubmit scripts?
b
an after submit script would not trigger other scripts
p
got it. I am trying to trigger it once a reject is made from a workflow.
I have tried a workflow action script and an aftersubmit script. The workflow action gives an error that the record has been submitted and the aftersubmit returns the same field values for the old and new records
b
what does your code look like
p
var oldrec = scriptContext.oldRecord; var rec = scriptContext.newRecord; var recordId = scriptContext.newRecord.id; var oldrecordid = scriptContext.oldRecord.id; var accountchanged = 0; var recordtype = record.Type.VENDOR_BILL; var oldrecord = record.load({ type: recordtype, id: oldrecordid }); var newapprovalstatus = rec.getValue({fieldId: 'status'}); var paymentneedsfixing = rec.getValue({fieldId: 'custbody_pi_paymentapplied'}); var oldapprovalstatus = oldrec.getText({fieldId: 'status'});
b
depends on the context on that one
the status of a record is set after the record has been submitted to netsuite
unless you manually change the status yourself
so changes to the status wont be reflected on the oldRecord or the newRecord
p
got it. When I try to set the value through a workflow action script I get a record has already been edited. Is there a way I can workaround this error?
b
both oldrec and rec should have the value of the old status
your badly named oldrecord should have the current data
in cases where the status field was actually changed by the user, then the oldrec will have the old status while oldrecord and rec will have the new changed status
you probably have to read that very carefully, your badly named variables makes that very confusing
p
got it. what about if the status is changed by another process?
b
no matter what happens, the oldrecord represents the current state of the record
since you just loaded it
p
got it. what about if I remove the record load?
b
then my previous statements stand
you will need an understanding of what i said before
p
thanks battk. I understand what you mean and I appreciate the help