【问题标题】:NetSuite SuiteTalk "customSearchJoin" access from SOAP XML Response来自 SOAP XML 响应的 NetSuite SuiteTalk“customSearchJoin”访问
【发布时间】:2016-01-19 15:57:06
【问题描述】:

我仍在对 NetSuite 进行热身,但遇到了一个我无法解决的问题。

我正在构建一个 C# 函数来从 NetSuite 的 XML SOAP 响应中提取信息。此 XML 是保存的搜索调用的结果,其中包含一个标题为 customSearchJoin 的连接部分,我不确定如何访问该部分。下面我将展示 XML 部分以及我在 C# 函数中访问它的尝试。

我正在尝试访问值为 091736418

的字段

XML 段:

    <platformCore:searchRow xsi:type="tranSales:TransactionSearchRow" xmlns:tranSales="urn:sales_2014_1.transactions.webservices.netsuite.com">
    <tranSales:basic xmlns:platformCommon="urn:common_2014_1.platform.webservices.netsuite.com">
        <platformCommon:dateCreated>
            <platformCore:searchValue>2015-12-17T08:43:00.000-08:00</platformCore:searchValue>
        </platformCommon:dateCreated>
        <platformCommon:entity>
            <platformCore:searchValue internalId="615"/>
        </platformCommon:entity>
    </tranSales:basic>
    <tranSales:customerMainJoin xmlns:platformCommon="urn:common_2014_1.platform.webservices.netsuite.com">
        <platformCommon:altName>
            <platformCore:searchValue>Some Specific Customer</platformCore:searchValue>
        </platformCommon:altName>
    </tranSales:customerMainJoin>
    <tranSales:itemJoin xmlns:platformCommon="urn:common_2014_1.platform.webservices.netsuite.com">
        <platformCommon:itemId>
            <platformCore:searchValue>Some Product</platformCore:searchValue>
        </platformCommon:itemId>
    </tranSales:itemJoin>
    <tranSales:customSearchJoin xmlns:platformCommon="urn:common_2014_1.platform.webservices.netsuite.com">
        <platformCommon:customizationRef internalId="167" scriptId="custrecord_itmfulfillmentid"/>
        <platformCommon:searchRowBasic xsi:type="platformCommon:CustomRecordSearchRowBasic">
            <platformCommon:recType internalId="25"/>
            <platformCommon:customFieldList>
                <platformCore:customField xsi:type="platformCore:SearchColumnStringCustomField" scriptId="custrecord_ssccbarcode" internalId="169">
                    <platformCore:searchValue>091736418</platformCore:searchValue>
                </platformCore:customField>
            </platformCommon:customFieldList>
        </platformCommon:searchRowBasic>
    </tranSales:customSearchJoin>
</platformCore:searchRow>

C#函数:

    private void testCustomJoinSearch() {

    TransactionSearchAdvanced transSearchAdv = new TransactionSearchAdvanced
    {
        savedSearchScriptId = "customsearch_savedSearchID"
    };

    SearchResult searchResult = _service.search(transSearchAdv);

                if (searchResult.status.isSuccess)
                {
                    Console.WriteLine("Search Success");

                    foreach (TransactionSearchRow transSearchRow in searchResult.searchRowList)
                    {

                        // declare vars
                        string transInternalID = "";
                        string ssccBarcode = "";

                        //normal field
                        transInternalID = transSearchRow.basic. internalId[0].searchValue.internalId.ToString();

                        //joined and custom field ? Not sure this loop is correct
                        foreach (CustomSearchRowBasic customBasicSearchRow in transSearchRow.customSearchJoin)
                        {
                                        // ????

                        };

                        Console.WriteLine("transInternalID {0}", transInternalID);
                        Console.WriteLine("ssccBarcode {0}", ssccBarcode);
                    } // end main search row
                }
                else
                {
                    Console.WriteLine("Search Failure");
                    Console.WriteLine(searchResult.status.statusDetail);
                }
}

【问题讨论】:

    标签: c# xml soap netsuite


    【解决方案1】:

    试试 xml linq。我修复了缺少一些命名空间定义的 xml,所以我添加了 root,然后关闭了结束标签 platformCore:searchRow 和 root。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace ConsoleApplication70
    {
        class Program
        {
            static void Main(string[] args)
            {
                string xml =
                    "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                    "<Root xmlns:platformCore=\"abc\" xmlns:xsi=\"def\">" +
                    "<platformCore:searchRow xsi:type=\"tranSales:TransactionSearchRow\" xmlns:tranSales=\"urn:sales_2014_1.transactions.webservices.netsuite.com\">" +
                    "<tranSales:basic xmlns:platformCommon=\"urn:common_2014_1.platform.webservices.netsuite.com\">" +
                        "<platformCommon:dateCreated>" +
                            "<platformCore:searchValue>2015-12-17T08:43:00.000-08:00</platformCore:searchValue>" +
                        "</platformCommon:dateCreated>" +
                        "<platformCommon:entity>" +
                            "<platformCore:searchValue internalId=\"615\"/>" +
                        "</platformCommon:entity>" +
                    "</tranSales:basic>" +
                    "<tranSales:customerMainJoin xmlns:platformCommon=\"urn:common_2014_1.platform.webservices.netsuite.com\">" +
                        "<platformCommon:altName>" +
                            "<platformCore:searchValue>Some Specific Customer</platformCore:searchValue>" +
                        "</platformCommon:altName>" +
                    "</tranSales:customerMainJoin>" +
                    "<tranSales:itemJoin xmlns:platformCommon=\"urn:common_2014_1.platform.webservices.netsuite.com\">" +
                        "<platformCommon:itemId>" +
                            "<platformCore:searchValue>Some Product</platformCore:searchValue>" +
                        "</platformCommon:itemId>" +
                    "</tranSales:itemJoin>" +
                    "<tranSales:customSearchJoin xmlns:platformCommon=\"urn:common_2014_1.platform.webservices.netsuite.com\">" +
                        "<platformCommon:customizationRef internalId=\"167\" scriptId=\"custrecord_itmfulfillmentid\"/>" +
                        "<platformCommon:searchRowBasic xsi:type=\"platformCommon:CustomRecordSearchRowBasic\">" +
                            "<platformCommon:recType internalId=\"25\"/>" +
                            "<platformCommon:customFieldList>" +
                                "<platformCore:customField xsi:type=\"platformCore:SearchColumnStringCustomField\" scriptId=\"custrecord_ssccbarcode\" internalId=\"169\">" +
                                    "<platformCore:searchValue>091736418</platformCore:searchValue>" +
                                "</platformCore:customField>" +
                            "</platformCommon:customFieldList>" +
                        "</platformCommon:searchRowBasic>" +
                    "</tranSales:customSearchJoin>" +
                    "</platformCore:searchRow>" +
                    "</Root>";
    
                XDocument doc = XDocument.Parse(xml);
    
                string searchvalue = doc.Descendants().Where(x => x.Name.LocalName == "customSearchJoin")
                    .Descendants().Where(y => y.Name.LocalName == "searchValue").Select(z => (string)z).FirstOrDefault();
    
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      我相信是这样的:

      foreach (CustomSearchRowBasic customBasicSearchRow in transSearchRow.customSearchJoin) {
          // ????
      
          CustomRecordSearchRowBasic itmfulfillmentidRecord = customBasicSearchRow.searchRowBasic as CustomRecordSearchRowBasic;
          foreach(SearchColumnCustomField customField in itmfulfillmentidRecord.customFieldList) {
              if (customField.scriptId == "custrecord_ssccbarcode") {
                  SearchColumnStringCustomField stringField = customField as SearchColumnStringCustomField;
      
                  string itmfulfillmentid = stringField.searchValue;
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-03
        相关资源
        最近更新 更多