Create Netsuite Customer with Addresses

Figuring out how to do address arrays on a Netsuite Customer can be rather complicated so I thought I would share some sample code:

$CustomerAddressBooks = array();
foreach ($addresses as $address) {
        //populate the approprate varables i.i. $street, $City, etc from $address
	$addrArray = array(
            "defaultBilling" => $DefaultBilling,
            "defaultShipping" => $DefaultShipping,
            "addr1" => $Street,
            "addr2" => $Street2,
            "label" => $Street,
            "city" => $City,
            "phone" => $Phone,
            "country" => $NsCountryCode,
            "addressee" => $Addressee,
            "attention" => $attention,
            "zip" => $Zip
        );
	$CustomerAddressBook = new nsComplexObject('CustomerAddressbook');
        $CustomerAddressBook->setFields($addrArray);
        $CustomerAddressBooks[] = $CustomerAddressBook;
}
$CustomerAddressBookList = new nsComplexObject('CustomerAddressbookList');
$CustomerAddressBookList->setFields(array(
    "addressbook" => $CustomerAddressBooks
));

$customerInformationArray = array(
            "email" => $email,
            "phone" => $phone,
            "addressbookList" => $CustomerAddressBookList,
            "creditCardsList" => $CCCList
);
This entry was posted in Netsuite PHPToolkit and tagged , , , . Bookmark the permalink.

11 Responses to Create Netsuite Customer with Addresses

  1. Michael says:

    Hi Daniel, thanks for the sample code as always!

    I am having some trouble figuring out how to retrieve and display the address from netsuite. I can retrieve and display nearly all other fields (i.e. internalId, firstname, lastname, company, phone, fax and email but cannot for the life of me get the address.

    Any tip would be greatly appreciated, please send me your email address so I can send a little thank you via paypal.

    Michael

  2. Michael says:

    Daniel,

    Thank you, as always your code snippets are a great help!

  3. Parker says:

    Worked like a charm… thanks for posting

  4. maysam says:

    hi

    how can we set value for custom fields for customer? any idea

    thanks

  5. Erik says:

    You can also just send an array (even with multiple addresses) and Netsuite does the rest. But – as in your solution as well – you won’t get the addresses internalID which is bad if you need to map Netsuite records with your own systems records.
    $addrArray = array(

    ‘addressbook’ => array(
    array(
    “addr1″ => $bill,
    “addr2″ => $billingAddress->getAddress4(),
    “city” => $billingAddress->getCity(),
    “zip” => $billingAddress->getPostcode(),
    ‘defaultBilling’ => ‘true’
    ),
    array(
    “addr1″ => $ship,
    “addr2″ => $shippingAddress->getAddress4(),
    “city” => $shippingAddress->getCity(),
    “zip” => $shippingAddress->getPostcode(),
    ‘defaultShipping’ => ‘true’
    )
    )
    );

  6. Vigneswaran says:

    Hi,
    Thanks in advance,
    Can we use upsert method to add/update Customer addressbook details (note: I don’t have internal id of the customer address book) ?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>