user2570937
user2570937

Reputation: 852

Add a customers address in netsuite using phptoolkit

I'm having trouble adding a customers address to netsuite. everything is working except for the address. This is the error im getting back:

Warning: Trying to assign an object into an array parameter "addressbook" of class "CustomerAddressbookList", it will be omitted

$service = new NetSuiteService();

$customer = new Customer();
$customerFields = array (
    'firstName'         => "Joe",
    'lastName'          => "Doe",
    'companyName'       => "ABC company5",
    'phone'     => "123456789",
    'email'             => "[email protected]",
    'addressbookList'   => array (
                'addressbook'   => array(
                        'addr1'     => "asdfsadf",
                        'city'      => "asfff",
                        'state'     => "asdf",
                        'zip'       => 2323
                )
        )
);
setFields($customer, $customerFields);

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

$addResponse = $service->add($request);

Upvotes: 0

Views: 1332

Answers (2)

Anthony Eden
Anthony Eden

Reputation: 152

The other answer here isn't quite correct. See this example code for adding an Address to a Customer:

$address = new Address();
$address->addr1 = '';
$address->addr2 = '';
$address->city = '';
$address->zip = '';
$address->state = '';
$address->country = '_australia';

$addressbook = new CustomerAddressbook();
$addressbook->defaultBilling = true;
$addressbook->addressbookAddress = $address;

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

$customer->addressbookList = $addressBook;

Upvotes: 0

Suite Resources
Suite Resources

Reputation: 1164

I always try to create records first, then tie them together later. Try something like this (untested, and off the top of my head):

Create addressbook entry.

    $customer = new Customer();

    ...

    $address = new CustomerAddressBook();
    $address->defaultShipping = false;
    $address->defaultBilling = false;
    $address->attention = "Attention Name";
    $address->addr1 = "Address 1";
    $address->city = "City";
    $address->zip = "12345";
    $address->state = "MA";

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


    $customer->addressbookList = $addressBook;

The rest of your code looks OK to me.

Upvotes: 1

Related Questions