将 NetSuite TransactionSearch 转换为仅返回 internalId 列的高级搜索

Posted

技术标签:

【中文标题】将 NetSuite TransactionSearch 转换为仅返回 internalId 列的高级搜索【英文标题】:Convert NetSuite TransactionSearch into Advanced Search with only internalId column to return 【发布时间】:2014-07-21 15:58:53 【问题描述】:

我有普通的事务搜索,SOAP 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<search xsi:type="sales:TransactionSearch" 
        xmlns="urn:messages_2013_1.platform.webservices.netsuite.com" 
        xmlns:sales="urn:sales_2013_1.transactions.webservices.netsuite.com" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:common="urn:common_2013_1.platform.webservices.netsuite.com" 
        xmlns:core="urn:core_2013_1.platform.webservices.netsuite.com">
    <sales:basic xsi:type="common:TransactionSearchBasic" xmlns:common="urn:common_2013_1.platform.webservices.netsuite.com">
        <common:type operator="anyOf" xsi:type="core:SearchEnumMultiSelectField">
            <core:searchValue xsi:type="xsd:string">_invoice</core:searchValue>
        </common:type>
        <common:customFieldList xsi:type="core:SearchCustomFieldList">          
            <core:customField operator="anyOf" xsi:type="core:SearchMultiSelectCustomField" internalId="custbodyintegrationstatus">
                <core:searchValue xsi:type="core:ListOrRecordRef" internalId="1" name="customlistintegrationstatuses"></core:searchValue>
            </core:customField>                 
        </common:customFieldList>
    </sales:basic>
</search>

此搜索现在可以在生产中使用,但有时当我运行此搜索时,我会在结果中得到 UNEXPECTED_ERROR。所以 NetSuite 的人建议改用高级搜索。 这个想法是找到所有具有自定义字段预定义值的发票,称为 custbodyintegrationstatus。自定义字段是一个值列表,我需要选择 internalId =“1”的值。我唯一想要回应的是每张找到的发票的 internalId。 问题是我不知道该怎么做。这是我的代码(C#):

TransactionSearchAdvanced advancedSearchEntity = new TransactionSearchAdvanced();

TransactionSearch ts = new TransactionSearch();
TransactionSearchBasic tsb = new TransactionSearchBasic();
// condition 1: on SO only
SearchEnumMultiSelectField semsfTranType = new SearchEnumMultiSelectField();
semsfTranType.operatorSpecified = true;
semsfTranType.@operator = SearchEnumMultiSelectFieldOperator.anyOf;
semsfTranType.searchValue = new[]"_salesOrder";


SearchMultiSelectCustomField spsIntegrationStatusField = new SearchMultiSelectCustomField();
spsIntegrationStatusField.operatorSpecified = true;
spsIntegrationStatusField.@operator = SearchMultiSelectFieldOperator.anyOf;
spsIntegrationStatusField.internalId = "custbodyintegrationstatus";

ListOrRecordRef searchRecordEntity = new ListOrRecordRef();
searchRecordEntity.name = "customlistintegrationstatuses";
searchRecordEntity.internalId = "1";        // indicates record status - ready / test ready / etc
spsIntegrationStatusField.searchValue = new[]  searchRecordEntity ;

tsb.type = semsfTranType;
tsb.customFieldList = new SearchCustomField[]  spsIntegrationStatusField ;

TransactionSearchRow tsr = new TransactionSearchRow();
TransactionSearchRowBasic tsrb = new TransactionSearchRowBasic();

SearchColumnSelectField[] selcols = new SearchColumnSelectField[1];
selcols[0] = new SearchColumnSelectField();

// Set return columns 
tsrb.internalId = selcols;
tsr.basic = tsrb;

ts.basic = tsb;
advancedSearchEntity.criteria = ts;
advancedSearchEntity.columns = tsr; //note - columns previously defined above.
_service.searchPreferences.returnSearchColumns = true;
SearchResult savedSearchResult = _service.search(advancedSearchEntity);

WebServices 使用日志中的 SOAP 请求如下所示:

<search xmlns="urn:messages_2013_1.platform.webservices.netsuite.com">
    <searchRecord xsi:type="q1:TransactionSearchAdvanced" xmlns:q1="urn:sales_2013_1.transactions.webservices.netsuite.com">
        <q1:criteria>
            <q1:basic>
                <type operator="anyOf" xmlns="urn:common_2013_1.platform.webservices.netsuite.com">
                    <searchValue xmlns="urn:core_2013_1.platform.webservices.netsuite.com">_salesOrder</searchValue>
                </type>
                <customFieldList xmlns="urn:common_2013_1.platform.webservices.netsuite.com">
                    <customField operator="anyOf" internalId="custbodyintegrationstatus" xsi:type="SearchMultiSelectCustomField" xmlns="urn:core_2013_1.platform.webservices.netsuite.com">
                        <searchValue internalId="1">
                            <name>customlistintegrationstatuses</name>
                        </searchValue>
                    </customField>
                </customFieldList>
            </q1:basic>
        </q1:criteria>
        <q1:columns>
            <q1:basic>
                <internalId xmlns="urn:common_2013_1.platform.webservices.netsuite.com"/>
            </q1:basic>
        </q1:columns>
    </searchRecord>
</search>

下面是回复:

<searchResponse xmlns="urn:messages_2013_1.platform.webservices.netsuite.com">
    <platformCore:searchResult xmlns:platformCore="urn:core_2013_1.platform.webservices.netsuite.com">
        <platformCore:status isSuccess="true"/>
        <platformCore:totalRecords>108956</platformCore:totalRecords>
        <platformCore:pageSize>5</platformCore:pageSize>
        <platformCore:totalPages>21792</platformCore:totalPages>
        <platformCore:pageIndex>1</platformCore:pageIndex>
        <platformCore:searchId>WEBSERVICES_TSTDRV961603_060120141461034810519911044_b227f55</platformCore:searchId>
        <platformCore:searchRowList>
            <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <tranSales:basic xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com">
                    <platformCommon:internalId>
                        <platformCore:searchValue internalId="134200"/>
                    </platformCommon:internalId>
                </tranSales:basic>
            </platformCore:searchRow>
            <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <tranSales:basic xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com">
                    <platformCommon:internalId>
                        <platformCore:searchValue internalId="134200"/>
                    </platformCommon:internalId>
                </tranSales:basic>
            </platformCore:searchRow>
            <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <tranSales:basic xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com">
                    <platformCommon:internalId>
                        <platformCore:searchValue internalId="134200"/>
                    </platformCommon:internalId>
                </tranSales:basic>
            </platformCore:searchRow>
            <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <tranSales:basic xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com">
                    <platformCommon:internalId>
                        <platformCore:searchValue internalId="134200"/>
                    </platformCommon:internalId>
                </tranSales:basic>
            </platformCore:searchRow>
            <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <tranSales:basic xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com">
                    <platformCommon:internalId>
                        <platformCore:searchValue internalId="134255"/>
                    </platformCommon:internalId>
                </tranSales:basic>
            </platformCore:searchRow>
        </platformCore:searchRowList>
    </platformCore:searchResult>
</searchResponse>

很明显,我做错了什么,即使没有在搜索行中取消排队 internalIds 也表明了这一点。所以,请告诉我有什么问题。 SOAP 或任何 C#/Java/etc 代码示例都会很有帮助。

【问题讨论】:

【参考方案1】:

Pipechang 是对的。正确的 SOAP 请求如下所示:

<search xmlns="urn:messages_2013_1.platform.webservices.netsuite.com">
            <searchRecord xsi:type="q1:TransactionSearchAdvanced" xmlns:q1="urn:sales_2013_1.transactions.webservices.netsuite.com">
                <q1:criteria>
                    <q1:basic>
                        <mainLine xmlns="urn:common_2013_1.platform.webservices.netsuite.com">
                            <searchValue xmlns="urn:core_2013_1.platform.webservices.netsuite.com">true</searchValue>
                        </mainLine>
                        <type operator="anyOf" xmlns="urn:common_2013_1.platform.webservices.netsuite.com">
                            <searchValue xmlns="urn:core_2013_1.platform.webservices.netsuite.com">_salesOrder</searchValue>
                        </type>
                        <customFieldList xmlns="urn:common_2013_1.platform.webservices.netsuite.com">
                            <customField operator="anyOf" internalId="custbodyintegrationstatus" xsi:type="SearchMultiSelectCustomField" xmlns="urn:core_2013_1.platform.webservices.netsuite.com">
                                <searchValue internalId="2">
                                    <name>customlistintegrationstatuses</name>
                                </searchValue>
                            </customField>
                        </customFieldList>
                    </q1:basic>
                </q1:criteria>
                <q1:columns>
                    <q1:basic>
                        <internalId xmlns="urn:common_2013_1.platform.webservices.netsuite.com"/>
                    </q1:basic>
                </q1:columns>
            </searchRecord>
        </search>

【讨论】:

嗨 Sergey Shafiev,你是如何为那些没有信用额度的客户创建发票的,我遇到了问题,如果你能与我分享一些细节,我将不胜感激***.com/questions/52686093/… 【参考方案2】:

尝试添加搜索过滤器 mainline = T 以删除重复项。另外,您实际上是否有 internalid =1 的记录?

【讨论】:

你能给我看看这个例子吗?我对 SuiteTalk 不是很熟悉。 实际上我不明白如何重复出现响应?每条记录都有自己独特的参数 - internalId。 它们实际上并不是重复的,您会看到事务默认返回所有行项目(每个事务上的项目)。因此,如果您在不查看顶层(主线 = F)的情况下进行搜索,Netsuite 看起来就像您在那里拥有的一样,内部 id 会多次返回。这是因为交易中的每个项目都有不同的价格/数量。例如,您在客户上搜索地址也会发生同样的情况。在这种情况下,您的搜索仅返回 2 条记录 - 134200 和 134255,但看起来是重复的。 pipechang,非常感谢,您添加 mainline = true 参数是对的。我已经修复了我的 SOAP 请求,它现在可以按预期工作了。 嗨@Sergey Shafiev,您是如何为那些没有信用额度的客户创建发票的,我遇到了问题,如果您能与我分享一些细节***.com/questions/52686093/…,我将不胜感激

以上是关于将 NetSuite TransactionSearch 转换为仅返回 internalId 列的高级搜索的主要内容,如果未能解决你的问题,请参考以下文章

Freemarker / Netsuite - 将变量分配给特定的项目数量

Netsuite 的 Apple Pay 集成

NetSuite - 对行项目进行排序

Netsuite 将搜索保存到 Suitelet 子列表

Netsuite - OneWorld 税收和 Nexus

获取 Netsuite 高级库存序列号的脚本