Chad Smith Chad Smith - 3 months ago 22
PHP Question

NetSuite add customer address

I have seen the other examples here on StackOverflow but neither are working for me, my code creates an address line in NetSuite but the addr1, city, state and zip are empty, the default billing and shipping do show false or if I set it to true it shows true so that part is updating.. The response doesn't show any errors. Any ideas?

Here is my code:

$customer = new Customer();
$customer->internalId = 16;
$customer->firstName = 'Joe';
$customer->middleName = 'A';
$customer->lastName = 'Smith';
$customer->email = 'joe@email.com';

$address = new CustomerAddressBook();
$address->defaultShipping = false;
$address->defaultBilling = false;
$address->isResidential = true;
$address->addr1 = '123 Street';
$address->city = 'New York';
$address->zip = '12345';
$address->state = 'NY';

$addressBook = new CustomerAddressbookList();
$addressBook->addressbook = array($address);
$addressBook->replaceAll = false;

// add address to cutomer
$customer->addressbookList = $addressBook;


$request = new UpdateRequest();
$request->record = $customer;

$netsuiteService = new NetSuiteService();
$response = $netsuiteService->update($request);

Answer
$address = new Address();
$address->addr1 = '123 Street';
$address->city = 'New York';
$address->zip = '12345';
$address->state = 'NY';

$address_book = new CustomerAddressBook();
$address_book->defaultShipping = false;
$address_book->defaultBilling = false;
$address_book->isResidential = true;
$address_book->addressbookAddress = $address;

$address_book_list = new CustomerAddressbookList();
$address_book_list->addressbook = $address_book;
$address_book_list->replaceAll = false;

$customer = new Customer();
$customer->internalId = 16;
$customer->firstName = 'Joe';
$customer->middleName = 'A';
$customer->lastName = 'Smith';
$customer->email = 'joe@email.com';
$customer->addressbookList = $address_book_list;


$request = new UpdateRequest();
$request->record = $customer;

$netsuiteService = new NetSuiteService();
$response = $netsuiteService->update($request);

if (!$response->writeResponse->status->isSuccess) {
    echo "UPDATE ERROR";
} else {
    echo "UPDATE SUCCESS, id " . $response->writeResponse->baseRef->internalId;
}
Comments