【发布时间】:2013-04-04 04:14:48
【问题描述】:
我接到了一个要完成的项目,客户要求从附加到每个客户的自定义记录中提供一个字段以显示在他们的网站上。我们在登录时与 Netsuite 集成,并将他们的数据保存在我们的数据库中,这样我们就不必继续访问 Netsuite(非常慢)。
登录时,我们访问 Netsuite 执行 SearchMultiSelectCustomField 并找到客户的公司,然后执行 CustomRecordSearchBasic 并使用他们的公司 ID 获取他们有权访问的项目列表。
我们遍历每个项目,然后遍历它们的自定义字段。其中一个字段的 typeId 为 -10,这意味着我们执行 ItemSearchBasic 来获取此项目的记录和项目的自定义字段,保存此项目的 internalId。
在这个循环的最后,我们有一个公司链接到的项目 ID 数组。我们还有公司 ID (custrecord_nn_item_customer) 和项目 ID (custrecord_nn_item_customer_list)。
我需要对自定义记录执行获取请求,以检查该客户是否已获得该项目的批准。
customrecord 的 ID 为“customrecord_custitem”,内部 ID 为“1”。 该记录有 3 个字段(尽管客户的 Netsuite 记录页面只显示了 2 个字段):
custrecord_lookup_item - 这是项目记录代码(上面的 custrecord_nn_item_customer_list) custrecord_custitem_code 是我需要的代码
我的问题(毕竟)是有没有人有任何示例或可以指出我如何访问附加到客户的自定义记录的正确方向?我认为提供了所有必要的信息,但我之前从未使用过 Netsuite 或 PHP 工具包。
$this->depends('netsuite');
$this->netsuite->start();
// get the "customer" (aka company) that the user's contact record belongs to
$companySearch = $this->netsuite->complexObject('SearchMultiSelectCustomField')
->setFields(array(
'searchValue' => new nsListOrRecordRef(array('internalId' => $companyId)),
'internalId' => 'custrecord_nn_item_customer',
'operator' => 'anyOf'
));
// Fetch items that the user's company has access to
$search = $this->netsuite->complexObject('CustomRecordSearchBasic')
->setFields(array(
'recType' => new nsCustomRecordRef(array(
'internalId' => 260,
'type' => 'customRecord')
),
'customFieldList' => array($companySearch)
));
$response = $this->netsuite->client->search($search);
// loop over the items
foreach($this->netsuite->complexToSimple($response->recordList) as $record){
//var_dump($record);
$processor = null;
$this_item = '';
$this_person = '';
// foreach custom field (all the fields we're interested in, common name etc. are custom)
foreach($record['customFieldList']['customField'] as $customField){
$processor = $customField['value'];
$id = $processor['internalId'];
$typeId = $processor['typeId'];
if($customField['internalId']=='custrecord_nn_item_customer'){
$this_person = $id;
}elseif($customField['internalId']=='custrecord_nn_item_customer_list'){
$this_item = $id;
}
// a typeId of -10 = an Inventory Item
if($typeId == -10){
// do an ItemSearchBasic to fetch the item with it's custom fields
$itemSearch = $this->netsuite->complexObject('ItemSearchBasic')
->setFields(array(
'internalId' => array(
'operator' => 'anyOf',
'searchValue' => array('type' => 'inventoryItem', 'internalId' => $id)
)
));
$itemSearch = $this->netsuite->client->search($itemSearch);
// foreach custom item field
if($v=@$this->netsuite->complexToSimple($itemSearch->recordList)){
foreach($v as $itemRecord){
//var_dump($itemRecord);
$item = array('id' => $itemRecord['internalId']);
$items[] = $item;
}
}
}
}
}
在 foreach 循环中,我需要获取公司 ID 的 customrecord 字段和项目 ID 的当前迭代。
【问题讨论】:
-
如果你分享一些代码,你更有可能得到实质性的帮助。
-
不用担心,已经添加了this引用的代码部分。
-
我不熟悉网络套件,所以我的建议是严格使用 php。您可能可以使用 var_dump 或 print_r 并查看它的内部外观,例如在您的 out foreach 循环中,您可以使用 var_dump($record);您还可以 get_class_methods($record) 看看是否存在任何明显的 getter 或 setter。
标签: php record toolkit netsuite