fullstack.studio
fullstack.studio

Reputation: 340

customer.copy : Please enter value(s) for: Customer ID exception is thrown

I try to create a copy of existing customer via script. To add it as a sub customer for other subsidiary. (eg US customer bought form amazon.CA)... anyway ...

I tried:

require('N/record', function (record) {
    var customer = {
        id: XXXXXX,
        type: record.Type.CUSTOMER,
        isDynamic: true /* I tried false too */
    }
    var new_customer = record.copy(customer);
    var new_customer_data = {
        subsidiary: XX,
        parent: XXXXXX,
        currency: XX
    };
    for (var key in new_customer_data) {
        new_customer.setValue({
            fieldId: key,
            value: new_customer_data[key]
        });
    }
    new_customer.save() /* ! this throws the exception "Please enter value(s) for: Customer ID" */
});

I checked the NS docs. but I found nothing related. I could get the necessary fields (.getValue ... & and record.create ... ) but... record.copy is nicer :) and addresses remains attached to the new customer (when a copy is created trough UI).

thx!

update

After few hours of more researches I found that the issue is related to auto-generate numbers. More precisely, is related to 'Allow Override' option of order numbers for the customers. If it's set to false : the script works perfectly(I tested in sandbox). But if it's set to true it throws an exception. I did more tests. When the customer is copied (via script) the entityId is affect with the original customer entityId, that blocks the .save() action. If I set entityID to null it doesn't work either. When I set the entityId with any unique value .save() action works fine (but this is not a solution for me.. not yet :) ).

Maybe there is a record/context field that I should used to auto-generate a new number e.g. "clone_rec.generate_new_CUSTOMER_ID = true " !? Some how Netsuite overrides that when a copy of customer is created via UI.

Upvotes: 1

Views: 844

Answers (1)

bknights
bknights

Reputation: 15367

The name of the customer is unique and is also wiped out by the copy operation.

You need to enter the new company name (or first and last names for an individual). Something like:

var new_customer_data = {
    subsidiary: XX,
    parent: XXXXXX,
    currency: XX,
    companyname: 'some new company name',
    autoname:true // this may not make a difference. Depends on how your account is configured. 
};

Upvotes: 0

Related Questions