使用Netsuite PHPToolKit向客户记录添加新地址

时间:2013-12-30 17:07:44

标签: php netsuite

我希望为现有客户AddressBook添加新地址。我可以为新客户添加地址,但在向现有客户添加/更新地址时,更新地址的自定义表单的InternalID是netsuite拒绝的负数。我的代码是关闭的,还是我需要更新不同的自定义形式。

$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);   

这会返回 “无效的自定义表单引用键-10002。”

2 个答案:

答案 0 :(得分:1)

解决方案是实际创建一个New Customer();而不是对现有客户进行baseref。它仍然是更新请求,但您将更新分配给现有客户的internalId。因此,地址更新代码如下所示:

$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);

答案 1 :(得分:0)

这对我来说似乎很奇怪。尝试将customform设置为NetSuite(-2)中活动的Customer表单的内部ID是标准的Customer表单,但在使用之前请确保它不是非活动的。

除此之外,我要说你必须查看可能会干扰你的脚本的其他脚本或工作流程,例如处理某些beforeSubit功能的脚本或工作流程。