Matt McThree
Matt McThree

Reputation: 21

Adding a new Address to a Customer Record with Netsuite PHPToolKit

I am looking to add a new Address to an existing customers AddressBook. I am able to add an address for a new customer, but when adding/updating an address to an existing customer, the InternalID of the customform to update the address is a negative number which netsuite is rejecting. Is my code off, or is there a different customform I need to update.

$shipService = new NetSuiteService();

$gr = new GetRequest();
$gr->baseRef = new RecordRef();
$gr->baseRef->internalId = $internalId;
$gr->baseRef->type = "customer";
$getResponse = $shipService->get($gr);

//look in response for customer record
$customer = $getResponse->readResponse->record;

//add new address
$address = new CustomerAddressBook();
$address->defaultShipping = true;
$address->defaultBilling = true;
$address->attention = $customer_first . ' ' . $customer_last;
$address->addr1 = $customer_addr1;
$address->addr2 = $customer_addr2;
$address->city = $customer_city;
$address->zip = $customer_zip;
$address->state = $customer_state;

//add new Address book list
$addressBook = new CustomerAddressbookList();
$addressBook->addressbook = array($address);
$addressBook->replaceAll = false;

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

$shipService2 = new NetSuiteService();
$addrRequest = new UpdateRequest();
$addrRequest->record = $customer;
$addrResponse = $shipService2->update($addrRequest);   

this returns "Invalid customform reference key -10002."

Upvotes: 1

Views: 3695

Answers (2)

Matt McThree
Matt McThree

Reputation: 21

The solution is to actually create a New Customer(); instead of doing a baseref to an existing customer. It is still an update request, but you assign the update to the internalId of an existing customer. So, the address update code looks like this:

$shipService = new NetSuiteService();

$address = new CustomerAddressBook();
$address->defaultShipping = true;
$address->defaultBilling = true;
$address->attention = $customer_first.' '.$customer_last;
$address->addr1 = $customer_addr1;
$address->addr2 = $customer_addr2;
$address->city = $customer_city;
$address->zip = $customer_zip;
$address->state = $customer_state;

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

$customer = new Customer();
$customer->addressbookList = $addressBook;
$customer->internalId = $internalId;

$customer->customForm = new RecordRef();
$customer->customForm->internalId = 24;

$customer->addressbookList = $addressBook;

$shipService2 = new NetSuiteService();
$addrRequest = new UpdateRequest();
$addrRequest->record = $customer;
$addrResponse = $shipService2->update($addrRequest);

Upvotes: 1

Suite Resources
Suite Resources

Reputation: 1164

This seems very odd to me. Try setting the customform to the internal ID of a Customer form that is active in NetSuite (-2) is the standard Customer form, but make sure it is not inactive before using it.

Other than that, I'd say you have to look at other scripts or workflows that could interfere with your script, such as one that would process some beforeSubit functionality.

Upvotes: 0

Related Questions