4

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);
Chad Smith
  • 177
  • 10

1 Answers1

6
$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;
}
Prabhu
  • 783
  • 2
  • 10
  • 35
  • Great, thanks! None of the other examples had the "new Address();" – Chad Smith Feb 19 '16 at 15:36
  • This link will be useful to you . https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2015_2/schema/record/customer.html – Prabhu Feb 19 '16 at 16:46
  • Just fyi... when you have the customer with the internalId=16, you don't need to also add the firstname, middle name, lastname and email if that info is already in the system.. Plus don't forget to add the field 'addressee' to the $address, since that'll have the name of the person at the address... Other than that, worked like a charm, thanks a bunch! – Malachi Aug 29 '16 at 15:44