Skip to content
Error ResolutionSuiteScript 2.xWorkflows

Fix: CANT_MODIFY_LOCKED_FLD — NetSuite Locked Field Error

A field is locked by a workflow state, approval process, or record status — and your script is trying to change it. Here's how to work around it.

CANT_MODIFY_LOCKED_FLD: You cannot modify a locked field.

Quick Reference

Error Code
CANT_MODIFY_LOCKED_FLD
Severity
low
Type
record
Versions
2024.1, 2024.2, 2025.1, 2025.2, 2026.1

Why This Happens

  • The record is in an approval state and the field is locked by the approval workflow
  • A Workflow State locks specific fields on the record
  • The record status prevents modification (e.g., a Closed Sales Order's line items are locked)
  • The field is sourced from a parent record and can't be directly modified (e.g., 'terms' sourced from the customer)
  • A User Event beforeSubmit script from another bundle is locking the field

How to Fix It

  1. Step 1: Identify who is locking the field

    Go to the record in the UI, enter edit mode, and try to modify the field manually. If it's greyed out, check: (1) Workflow states — go to the record's Workflow History subtab, (2) Approval routing — check if the transaction is pending approval, (3) Record status — a Closed or Voided transaction has many locked fields.

  2. Step 2: Check Workflow field locks

    Go to Customization > Workflow. Open each workflow that applies to this record type. In each State, check the 'Fields' subtab — it shows which fields are locked in that state. Either unlock the field in the relevant state, or change your script to only modify the record when it's in a different state.

  3. Step 3: Re-open the record before modifying

    If the record is Closed, you may need to reopen it first: record.submitFields({ type, id, values: { status: 'open' } }). Modify the fields, then close it again. Some record types have specific reopen methods — check the Records Browser.

  4. Step 4: Use dynamic mode to bypass certain locks

    Loading a record in dynamic mode (record.load({ type, id, isDynamic: true })) sometimes allows modification of fields that are locked in standard mode. This is undocumented and may not work in all cases — test thoroughly.

Code Example

handle-locked-field.jsGov: 20u
/**
 * @NApiVersion 2.1
 *
 * Pattern: check record status before modifying fields that might be locked.
 * Avoids CANT_MODIFY_LOCKED_FLD by verifying state first.
 */
define(['N/record', 'N/search', 'N/log'], (record, search, log) => {

  /**
   * Safely updates a field, handling the locked-field scenario.
   * Returns the record ID if successful, or null if the field is locked.
   */
  function updateFieldSafely(type, id, fieldId, value) {
    // Pre-check: look up the current record status
    const lookupResult = search.lookupFields({
      type,
      id,
      columns: ['status', fieldId]
    });

    const status = lookupResult.status?.[0]?.value || '';
    const currentValue = lookupResult[fieldId];

    log.debug('updateFieldSafely', `Record ${type} #${id} status: ${status}, current ${fieldId}: ${currentValue}`);

    // Avoid writing if value is already correct (saves governance)
    if (String(currentValue) === String(value)) {
      log.debug('updateFieldSafely', 'Value unchanged — skipping update');
      return id;
    }

    try {
      record.submitFields({ type, id, values: { [fieldId]: value } });
      return id;
    } catch (e) {
      if (e.name === 'CANT_MODIFY_LOCKED_FLD') {
        log.audit('Locked field', `${type} #${id} field '${fieldId}' is locked (status: ${status}). Skipping.`);
        return null;
      }
      throw e; // Re-throw non-lock errors
    }
  }

  return { updateFieldSafely };
});

Common Mistakes

  • Trying to override workflow field locks by loading the record in SuiteScript — the lock applies regardless of how you access the record
  • Not checking the Workflow History subtab — a record can be in a locked workflow state even if no approval banner is visible
  • Assuming all fields lock at the same time — a workflow state can lock field A but leave field B editable
  • Using record.delete() to 'unlock' a record — this deletes it permanently, it doesn't unlock fields

Alternative Approaches

  • If you own the workflow, add a Workflow Action Script in the locked state that performs the field update — actions can modify fields that are locked for external access
  • Use a beforeSubmit User Event with a context check — if the record is being modified by a specific workflow transition, allow the change
  • Store the pending update in a custom record and apply it when the workflow transitions to an unlocked state

Related Errors