我正在尝试使用他们的PHP工具包将销售订单添加到netsuite中,但这会引发错误。
自定义价格级别ID为1 ADD ERROR
任何想法我做错了什么?我正在使用他们包含的样本文件。
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$svr = new getSelectValueRequest();
$svr->fieldDescription = new GetSelectValueFieldDescription();
$svr->pageIndex = 1;
/*$svr->fieldDescription->recordType = RecordType::salesOrder;
$svr->fieldDescription->sublist = "itemList";
$svr->fieldDescription->field = "price";
$svr->fieldDescription->
*/
$priceFields = array(
'recordType' => RecordType::salesOrder,
'sublist' => 'itemList',
'field' => 'price',
'filterByValueList' => array(
'filterBy' => array(
array(
'field' => 'item',
'sublist' => 'itemList',
'internalId' => '458',
)
)
)
);
setFields($svr->fieldDescription, $priceFields);
$gsv = $service->getSelectValue($svr);
$id = null;
foreach($gsv->getSelectValueResult->baseRefList->baseRef as $pricelevel) {
if ($pricelevel->name == 'Base Price') {
$id = $pricelevel->internalId;
break;
}
}
if ($id != null) {
echo "Custom price level id is " . $id . "\n";
} else {
echo "Custom price level not found " . $id . "\n";
}
$so = new SalesOrder();
$so->entity = new RecordRef();
$so->entity->internalId = 21;
$so->itemList = new SalesOrderItemList();
$soi = new SalesOrderItem();
$soi->item = new RecordRef();
$soi->item->internalId = 104;
$soi->quantity = 3;
$soi->price = new RecordRef();
$soi->price->internalId = $id;
$soi->amount = 55.3;
$so->itemList->item = array($soi);
$request = new AddRequest();
$request->record = $so;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
exit();
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
?>
答案 0 :(得分:1)
圣洁的抽烟!
价格水平 - 如果您正在寻找基础价格的ID,它将是1.总是。不需要任何循环或查找 - 它只是1.您可以修改价格级别的名称,甚至是基本价格,因此如果有人重命名,您的代码将会失败。
销售订单本身 - 我通常喜欢单独创建RecordRef,然后将它们分配到销售订单字段。
$entityRR = new RecordRef();
$entityRR->internalId = 21;
$entityRR->recordType = "customer";
$so->entity = $entityRR;
...
对于项目列表,你应该可以做这样的事情(在我的头顶和未经测试,但给你一般的想法):
$item = new SalesOrderItem();
$itemRR = new RecordRef();
$itemRR->internalId = 104;
$itemRR->recordType = "inventoryItem";
$pricelevelRR = new RecordRef();
$pricelevelRR->internalId = -1;
$pricelevelRR->recordType = "priceLevel";
$item->item = $itemRR;
$item->quantity = 1;
$item->price = $pricelevelRR;
$item->rate = 55.3;
$so->itemList = array($item);
注意:Amount字段是只读的。它是数量*率,并在Read请求中填充。此外,如果您提供的是Rate值而不使用其中一个价格级别,则将价格级别设置为“Custom”,即-1。
实际添加订单的其余代码看起来还不错。