This topic contains 3 replies, has 0 voices, and was last updated by mwhite@hgyp.com 7 years ago.

  • Author
    Posts
  • #21424

    kentroylance

    All of the sudden, I am getting this DUP_ENTITY error, and I have tried everything to get past this. In the past I have set the entityid with and without a unique id, and nothing seems to work. I am trying to create a customer record within a restlet that has worked fine in the past, and all of the sudden it stopped working. I have made sure all of the fields are unique and still get this error. I am at a loss how to get past it. Any suggestions?

    this is my endpoint: https://rest.na3.netsuite.com

    Content: "{"error" : {"code" : "Error", "message" : "ERROR: Failed to create customer. nCode: DUP_ENTITYnDetails: This entity already exists."}}", StatusCode: BadRequest, StatusDescription: "Bad Request"

    Here is my code:

    function createCustomer(input) {

    nlapiLogExecution('DEBUG', 'createCustomer()', 'firstname = ' + input.firstname + ', lastname = ' + input.lastname);

    var id = '';

    var status = '7';

    var stage = 'lead';

    var defaultSubsidiary = 1;

    try {

    var customer = nlapiCreateRecord('customer', { stage: stage });

    customer.setFieldValue("custentity_impartner", 'T');

    customer.setFieldValue("custentity_is_deal_registr ation", 'T');

    customer.setFieldValue('entitystatus', status);

    customer.setFieldValue('subsidiary', defaultSubsidiary);

    customer.setFieldValue('isperson', 'T');

    customer.setFieldValue('isinactive', 'F');

    customer.setFieldValue('isprivate', 'F');

    customer.selectNewLineItem('addressbook');

    customer.setCurrentLineItemValue('addressbook', 'defaultshipping', 'T');

    customer.setCurrentLineItemValue('addressbook', 'defaultbilling', 'T');

    customer.setCurrentLineItemValue('addressbook', 'label', 'Primary Address');

    customer.setCurrentLineItemValue('addressbook', 'isresidential', 'F');

    customer.setFieldValue('entityid', input.firstname + ' ' + input.lastname);

    var address = customer.createCurrentLineItemSubrecord('addressbo ok', 'addressbookaddress');

    address.setFieldValue('attention', input.salutation + ' ' + input.firstname + ' ' + input.lastname);

    nlapiLogExecution('DEBUG', 'createCustomer()', 'stage = ' + stage + ', entitystatus = ' + status);

    for (var fieldname in input) {

    if (input.hasOwnProperty(fieldname)) {

    if (fieldname != "recordtype" && fieldname != "id") {

    var value = input[fieldname];

    if ((fieldname != 'addressee') && (fieldname != 'addr1') && (fieldname != 'city') && (fieldname != 'state') && (fieldname != 'zip') && (fieldname != 'country')) {

    if (value && typeof value != 'object') {

    customer.setFieldValue(fieldname, value);

    nlapiLogExecution('DEBUG', 'createCustomer()', 'fieldname: ' + fieldname + ', value: ' + value);

    } else {

    customer.setFieldValues(fieldname, value);

    }

    } else {

    if (value && typeof value != 'object') {

    customer.setLineItemValue('addressbook', fieldname, 1, value);

    nlapiLogExecution('DEBUG', 'createCustomer() addressbook', 'fieldname: ' + fieldname + ', value: ' + value);

    }

    }

    }

    }

    }

    //commit subrecord and line item

    address.commit();

    customer.commitLineItem('addressbook');

    var id = nlapiSubmitRecord(customer);

    nlapiLogExecution('DEBUG', 'createCustomer()', 'Created customer id: ' + id);

    } catch (ex) {

    var message = 'ERROR: Failed to create customer. ' + ex;

    nlapiLogExecution('ERROR', 'createCustomer()', message);

    throw nlapiCreateError('Error', message, true);

    }

    return id;

    }
    This is a cached copy. Click here to see the original post.

  • #21425

    mwhite@hgyp.com

    Make sure you look at inactive entities. I've found duplicates hiding there.


    kentroylance replied on 11/09/2017, 07:00 AM: how would I know what the inactive entities are? Thanks

  • #21426

    kentroylance

    Believe it or not, my culprit is the externalid field. If I remove the externalid field, I don't get an DUP ENTITY error. If I add this "externalid":"333342", I get the error. Before I upgraded to the latest version of NetSuite, I had no issues with this field. Are there dependencies on this field?

  • #21427

    mwhite@hgyp.com

    Sort of. The externalid has to be unique now. We've run into this with our HR integration when someone is transferred to a new subsidiary. I ended up creating an employee saved search sorted by the externalid.

You must be logged in to reply to this topic.