The quick answer
For an existing stored record, setting context.newRecord in beforeLoad does not update the database record. Use beforeSubmit when a field value must be written with the user's Save. Change the function and its returned export, keep the intended event guard, and verify the value after a fresh load.
This walkthrough uses a fictional invoice and a local code editor, stand-in API model, and saved transaction. The result proves persistence in that local exercise only. It does not upload a script or verify execution in a NetSuite account.
Before you start
The example changes the standard Memo field on an existing Invoice. An account-specific custom checkbox has the same lifecycle question, but its field type, ID, permissions, form and competing customizations need separate checks.
For account use, enable Server SuiteScript and use a role with the relevant transaction and scripting permissions. Upload the current source to the File Cabinet, associate it with a User Event script, and confirm the Invoice deployment is deployed and applicable to the intended user. Testing generally limits execution to the script owner; check status, owner, audience and execution role separately. The recording inspects prepared local script information rather than performing account deployment.
Oracle documents the existing-record limit in beforeLoad(context) and the write behavior in beforeSubmit(context). User Event scripts cannot override custom field permissions. A mismatch between the user's role permissions and custom field permissions can prevent beforeSubmit from updating that field, even when execution is set to Administrator.
01. Inspect stored data
In the local invoice view, open INV-7246 for Harborline Services. Memo reads Inspection pending, and the invoice total is 192.00. Keep this existing invoice as the comparison point.
02. Compare memory and storage
In the local Code Editor, invoice_memo_rule.js exports beforeLoad. Its EDIT-only assignment in the stand-in model is shown below. The model permits this call for teaching purposes; it does not prove that native beforeLoad accepts the assignment:
context.newRecord.setValue({
fieldId: 'memo',
value: 'Inspection reviewed'
});
Click Run local harness. This model executes the source against a stand-in record object. Memory reads Inspection reviewed, while its stored model remains Inspection pending. The output is a teaching model, not a native execution log or proof that the invoice was saved.
Click Save, then Run local exercise to apply the same saved source bytes to the local invoice example.
03. Reopen the invoice
In the local invoice editor, open INV-7246 in Edit. In this exercise, Memo remains Inspection pending. Opening an existing record did not submit a write. Click Cancel without saving.
04. Move the rule
Change both the function declaration and returned export to beforeSubmit. User Event newRecord objects are in standard mode; the body-field setValue API used here fits that mode:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([], () => {
function beforeSubmit(context) {
if (context.type !==
context.UserEventType.EDIT) return;
context.newRecord.setValue({
fieldId: 'memo',
value: 'Inspection reviewed'
});
}
return {beforeSubmit};
});
This fixed-value example replaces Memo on every matching EDIT submission. Replace its condition and value to fit the actual requirement. It does not cover CREATE, inline editing or other event types.
Save the file and run the local exercise. The independent API model now reports the value that its simulated submission would store. This output has not saved the invoice shown in the next step; that invoice still has its original Memo until its own Save.
Inspect the prepared Invoice Memo Rule script. The Script File is invoice_memo_rule.js. Before Submit Function is checked and Before Load Function is clear. These local indicators follow the saved source exports. In an account, verify the recognized entry point and applicable deployment separately.
05. Submit normally
Reopen INV-7246 in the local editor. Its Memo is still Inspection pending before submission. Click the invoice's Save without typing a new Memo. This local Save submits an edit and applies the beforeSubmit assignment to the pending write.
There is no newRecord.save() inside the script. The user submits the invoice; beforeSubmit changes the record NetSuite is about to write. The transaction must still pass validation and save successfully.
06. Reload the saved value
The local View screen now shows Inspection reviewed. Reload the invoice and confirm that Memo remains Inspection reviewed. The observed total stays 192.00. That is the local persistence check; it does not establish other fields or native account behavior.
Common questions
Why can a log show the new value even though it does not persist?
A record object and stored transaction data are different states. An immediate getValue result can describe the object used in that invocation. It does not prove a write occurred or establish that native beforeLoad accepted a change. The local model makes that distinction visible; the account's actual form display can depend on its context and customizations.
Does Store Value make beforeLoad changes persist?
Store Value does not turn a load event into an update operation on an existing record. A stored custom field still needs an appropriate write path, such as beforeSubmit during a submitted edit, with the required permissions.
Does ignoreFieldChange fix this?
No. That option does not change beforeLoad into a record-write event. Choose the correct entry point and verify persistence after the actual submission.
Can beforeLoad set defaults for a new record?
New-record initialization is a different case. beforeLoad can supply values for a new record that is later saved; the existing-record result here should not be generalized to CREATE. This recording does not demonstrate CREATE behavior.
Should I force persistence by saving inside beforeLoad?
Use the normal write path for the requirement. In this example, the user saves the invoice and beforeSubmit changes the pending record. Adding a save during beforeLoad is not the demonstrated fix.