简体   繁体   English

Netsuite-使用PHP工具包获取自定义记录

[英]Netsuite - get custom record with php toolkit

I've been handed a project to complete and the clients have asked for a field from a customrecord attached to each customer to appear on their website. 我已经完成了一个项目,客户已经要求附加到每个客户的customrecord中的字段出现在他们的网站上。 We're integrating with Netsuite on login, and saving their data in our database so we don't have to keep accessing Netsuite (very slow). 我们将在登录时与Netsuite集成,并将其数据保存在我们的数据库中,因此我们不必继续访问Netsuite(非常慢)。

On login, we access Netsuite to do a SearchMultiSelectCustomField and find the customer's company, and then do a CustomRecordSearchBasic and use their company ID to get a list of items they have access to. 登录时,我们访问Netsuite以执行SearchMultiSelectCustomField并找到客户的公司,然后执行CustomRecordSearchBasic并使用其公司ID来获取他们有权访问的项目的列表。

We loop over each of those items, and then loop over their custom fields. 我们遍历每个项目,然后遍历其自定义字段。 One of the fields has a typeId of -10, which means we do an ItemSearchBasic to get this item's record and the item's custom fields, saving the internalId of this item. 其中一个字段的typeId为-10,这意味着我们执行ItemSearchBasic来获取该项目的记录和该项目的自定义字段,并保存该项目的internalId。

At the end of this loop, we have an array of item IDs that a company is linked to. 在此循环的最后,我们有一个公司链接到的项目ID数组。 We also have the company ID (custrecord_nn_item_customer) and the Item ID (custrecord_nn_item_customer_list). 我们还具有公司ID(custrecord_nn_item_customer)和项目ID(custrecord_nn_item_customer_list)。

I need to perform a get request on a custom record to check if that customer has been approved for that item. 我需要在自定义记录上执行获取请求,以检查该客户是否已获得该商品的批准。

The customrecord's ID is 'customrecord_custitem', and internal Id is '1'. customrecord的ID为'customrecord_custitem',内部ID为'1'。 The record has 3 fields (although only 2 show up for the customer's Netsuite Record page): 该记录具有3个字段(尽管客户的Netsuite记录页面仅显示2个字段):

custrecord_lookup_item - this is the Item record code (custrecord_nn_item_customer_list from above) custrecord_custitem_code is the code I need custrecord_lookup_item-这是商品记录代码(上面的custrecord_nn_item_customer_list)custrecord_custitem_code是我需要的代码

My question (after all that) is does anyone have any examples or can point me in the right direction on how I can access a customrecord attached to a customer? 我的问题(毕竟)是没有人有任何示例,或者可以为我指出如何访问附加到客户的customrecord的正确方向? I think all of the necessary information is provided, but I've never used Netsuite before or the PHP toolkit. 我认为已经提供了所有必要的信息,但是我以前从未使用过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;
                    }
                }
            }
        }
    }

It is inside the foreach loop that I need to get the customrecord field for the company ID and the current iteration of the item ID. 我需要在foreach循环中获取公司ID和项目ID的当前迭代的customrecord字段。

Set up a saved search with the results columns you need. 使用所需的结果列设置保存的搜索。 Don't worry about filtering by customer. 不用担心被客户过滤。

Call the search from your code, and dynamically filter for the current customer. 从您的代码中调用搜索,并动态筛选当前客户。

Your code should be about 5-10 lines long to get that done, and should be super quick. 您的代码大约需要5至10行才能完成,并且应该超级快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM