Contact Us
A person working at a computer while another watches, and a third points out specific points, illustrating collaboration and communication.

Fix the “Please Enter Value(s) for: Address” SuiteScript Error

When removing customer address lines using SuiteScript 2.x, you may encounter the error “Please enter value(s) for: Address.”

One possible cause is the way your script iterates through the customer's addressbook sublist.

If you remove a line while looping forward through the sublist, the remaining lines shift positions. Your script may then attempt to access an incorrect line index or skip an address.

A simple way to avoid this indexing problem is to iterate through the sublist backward, from the last line to the first.

Why Removing Address Lines Can Cause Problems

NetSuite's record.removeLine() method removes a line from a sublist.

When that happens, the remaining lines are reindexed.

For example, suppose a customer has four address lines:

Original indexAddress
0Address A
1Address B
2Address C
3Address D

If your script removes Address B at index 1, the remaining addresses shift:

New indexAddress
0Address A
1Address C
2Address D

Address C is now at index 1 rather than index 2.

A forward loop that continues incrementing its index may skip Address C or eventually attempt to access a line that no longer exists.

This is particularly problematic when a script needs to inspect and potentially remove multiple address lines.

Solution: Iterate Through the Addressbook Backward

Instead of looping forward:

for (var i = 0; i < addressLines; i++) {
    // Process address line
}

Loop backward:

for (var i = addressLines - 1; i >= 0; i--) {
    // Process address line
}

When you remove a line while iterating backward, the indices of the remaining unprocessed lines do not change.

This allows your script to continue examining the preceding address lines without skipping them.

SuiteScript 2.x Example: Remove Temporary Customer Addresses

The following example demonstrates how to:

  1. Load a customer record.
  2. Count the customer's addressbook lines.
  3. Iterate through the addressbook backward.
  4. Remove addresses marked as temporary.
  5. Set the default shipping address based on its label.
  6. Save the updated customer record.
/**
 * @NApiVersion 2.1
 */

define(['N/record'], (record) => {

    function updateCustomerAddresses(customerId) {
        const customerRecord = record.load({
            type: record.Type.CUSTOMER,
            id: customerId,
            isDynamic: false
        });

        const DEFAULT_SHIPPING_ADDRESS_LABEL = 'delivery';

        const addressLines = customerRecord.getLineCount({
            sublistId: 'addressbook'
        });

        for (let i = addressLines - 1; i >= 0; i--) {
            const addressSubrecord =
                customerRecord.getSublistSubrecord({
                    sublistId: 'addressbook',
                    fieldId: 'addressbookaddress',
                    line: i
                });

            const isTemporary = addressSubrecord.getValue({
                fieldId: 'custrecord_temp_address'
            });

            if (isTemporary) {
                customerRecord.removeLine({
                    sublistId: 'addressbook',
                    line: i,
                    ignoreRecalc: true
                });

                continue;
            }

            const addressLabel = customerRecord.getSublistValue({
                sublistId: 'addressbook',
                fieldId: 'label',
                line: i
            });

            const normalizedLabel = addressLabel
                ? String(addressLabel).trim().toLowerCase()
                : '';

            const isDefaultShipping =
                normalizedLabel === DEFAULT_SHIPPING_ADDRESS_LABEL;

            customerRecord.setSublistValue({
                sublistId: 'addressbook',
                fieldId: 'defaultshipping',
                line: i,
                value: isDefaultShipping
            });
        }

        return customerRecord.save();
    }

    return {
        updateCustomerAddresses
    };
});

Understanding the Code

Load the customer record

The script uses record.load() to retrieve the customer record and its addressbook sublist.

Get the address line count

The getLineCount() method determines how many addresses are associated with the customer.

Loop from the last line to the first

The loop starts at addressLines - 1 and decrements the index after each iteration.

Check whether an address is temporary

The script reads custrecord_temp_address from the address subrecord.

This is an example of an implementation-specific custom field. The field ID and its availability depend on your NetSuite configuration.

Remove temporary addresses

When the temporary-address flag is true, removeLine() removes the addressbook entry.

The continue statement moves the loop to the next address without attempting to update the removed line.

Identify the default shipping address

For addresses that remain, the script checks the address label.

If the normalized label is delivery, the script sets the addressbook line's defaultshipping field to true.

Save the customer record

After processing the addressbook, the script saves the customer record.

What If the Address Error Still Appears?

Reverse iteration prevents a specific class of sublist indexing problems. However, the error message may also occur when NetSuite encounters invalid or incomplete address information.

If the error continues, investigate the following possibilities.

1. Missing Mandatory Address Information

Check whether any remaining address subrecords are missing required values.

The required fields may depend on the country and the account's address configuration.

2. Incorrect Address Subrecord Field IDs

Confirm that the script references the correct fields on the address subrecord.

The custom field custrecord_temp_address must exist and be accessible in the relevant configuration.

3. An Invalid Default Shipping Address

Review whether the script is assigning the default shipping flag to an address that remains on the customer record.

If no remaining address has the expected label, the script may leave the customer without the intended default shipping address.

4. Standard Mode vs. Dynamic Mode

The example uses standard-mode record APIs, including getSublistValue() and setSublistValue().

If your script loads the record in dynamic mode, the sublist editing approach may need to change.

5. Record Save Validation

An error may occur during customerRecord.save() rather than during removeLine().

If the loop completes but saving fails, inspect the remaining address subrecords and any mandatory-field requirements.

Final Thoughts

When removing lines from a NetSuite sublist, iterating backward is a useful way to avoid index-shifting problems.

Instead of starting at index 0 and moving forward, begin with the last line and work toward the first.

This approach is useful when deleting customer addressbook entries and can also be applied to other sublists where multiple lines need to be removed.

If the “Please enter value(s) for: Address” error persists after changing the loop, review the address data and record validation requirements to identify the underlying cause.

Related Articles

Tagged with Troubleshooting