I am attempting to create a RESTlet that will receive a JSON data payload and will create a customer record. When testing my RESTlet I receive the following error message:
{"error" : {"code" : "JS_EXCEPTION", "message" : "You cannot save this record without providing both Default Shipping Address and a Default Billing Address."}} Below is my RESTlet code: function add_createRecord(datain) { var fieldname; var recordID; var updateID; var record; var err; var value; var status; if(!datain.recordtype) { err.status = "failed"; err.message = "payload recordtype missing"; return err; } else if ((datain.status == 'update') && (!datain.recordid)) { err.status = "failed"; err.message = "payload set to update, missing record id"; return err; } status = datain.status; if(status == 'create') { record = nlapiCreateRecord(datain.recordtype,'dynamic'); for(fieldname in datain) { if(datain.hasOwnProperty(fieldname)) { if((fieldname != 'recordtype') || (fieldname != 'status') || (fieldname != 'recordid')) { if(fieldname != 'address') { value = datain[fieldname]; if(value && typeof value != 'object') { record.setFieldValue(fieldname, value); } } else { nlapiSelectNewLineItem('addressbook'); for(addressfield in datain["address"][0]) { nlapiLogExecution('DEBUG','Address Values','value:'+datain["address"][0][addressfield]+', type:'+typeof(datain["address"])); value = datain["address"][0][addressfield]; nlapiLogExecution('DEBUG','Address Fields','fieldname:'+addressfield+', value:'+value); nlapiSetCurrentLineItemValue('addressbook',addressfield,value,true,true); } nlapiCommitLineItem('addressbook'); nlapiSelectNewLineItem('addressbook'); for(addressfield in datain["address"][1]) { nlapiLogExecution('DEBUG','Address Values','value:'+datain["address"][0][addressfield]+', type:'+typeof(datain["address"])); value = datain["address"][1][addressfield]; nlapiLogExecution('DEBUG','Address Fields','fieldname:'+addressfield+', value:'+value); nlapiSetCurrentLineItemValue('addressbook',addressfield,value,true,true); } nlapiCommitLineItem('addressbook'); } } } } } } Below is my JSON data payload: { "recordtype": "customer", "status": "create", "recordid": "", "customform": "39", "companyname": "John W Smith, TEST", "entitystatus": "13", "custentity_industry": "23", "custentity_class": "49", "phone": "(248) 555-5555", "email": "test@email.com", "custentity_department": "402", "leadsource": "282", "currency": "1", "subsidiary": "1", "address": [ { "defaultshipping": "T", "defaultbilling": "F", "addressee": "John W Smith", "addr1": "5555 Any St", "addr2": "", "city": "Troy", "country": "United States", "zip": "48085", "state": "MI" }, { "defaultbilling": "T", "defaultshipping": "F", "addressee": "John W Smith", "addr1": "5555 Any St", "addr2": "", "city": "Troy", "country": "United States", "zip": "48085", "state": "MI" } ] } Any help in this endeavor would be very appreciated.