我需要使用php工具包删除地址簿列表中已有的客户地址。 这是我的代码,
$service = new NetSuiteService();
$addressbook = new CustomerAddressBook();
$addressbook->internalId = 'xxxxxx'; // addressBook Record (a entire row) interanl id
$addressBookList = new CustomerAddressbookList();
$addressBookList->addressbook = $addressbook;
$addressBookList->replaceAll = false;
$customer = new Customer();
$customer->internalId = $_SESSION["customer_internalId"]; // customer internal ID
$customer->addressbookList = $addressBookList;
$deleteRequest = new DeleteRequest();
$deleteRequest->record = $customer;
$deleteResponse = $service->delete($deleteRequest);
print_r( $deleteResponse );
当我运行此代码时,我得到了异常“BaseRef是一种抽象类型,无法在...中实例化”。如何为客户删除地址簿列表中的多个地址之一?
答案 0 :(得分:2)
我认为您不能删除客户记录中的特定子记录。
点击此处查看deleted record types
我会做一个更新请求,只是从地址簿中删除我不想要的地址。像这样......
<?php
$service = new NetSuiteService();
$service->setPreferences(false, true, true, true);
$gr = new GetRequest();
$gr->baseRef = new RecordRef();
$gr->baseRef->internalId = $_SESSION["customer_internalId"]; //customer internal id
$gr->baseRef->type = "customer";
$getResponse = $service->get($gr);
if (!$getResponse->readResponse->status->isSuccess)
{
echo "GET ERROR";
}
else
{
echo "GET SUCCESS";
}
$customer = $getResponse->readResponse->record;
$arrayAddressBook = $customer->addressbookList->addressbook;
// find matching addressbook
$findAddressKey = array_filter($arrayAddressBook,
function ($e)
{
return $e->internalId == 'xxxxxx'
// addressbook internal id;
});
// grab key of that addressbook object to remove
$addressKey = key($findAddressKey);
unset($arrayAddressBook[$addressKey]);
$customer->addressbookList->replaceAll = true;
$customer->addressbookList->addressbook = $arrayAddressBook;
$request = new UpdateRequest();
$request->record = $customer;
$service->setPreferences(false, false, false, true);
$updateResponse = $service->update($request);
if (!$updateResponse->writeResponse->status->isSuccess)
{
echo "UPDATE ERROR";
}
else
{
echo "UPDATE SUCCESS, id " . $updateResponse->writeResponse->baseRef- >internalId;
}
?>