从SOAP XML Response访问NetSuite SuiteTalk“customSearchJoin”

时间:2016-01-19 15:57:07

标签: c# xml soap netsuite

我仍然对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);
                }
}

2 个答案:

答案 0 :(得分:0)

试试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();

        }
    }
}

答案 1 :(得分:0)

我相信它是这样的:

var user = ctx.get_web().get_currentUser();
        ctx.load(user);

        var userName;
        ctx.executeQueryAsync(function(){
                userName = user.get_loginName(); 
                alert(userName);
                }, function(){alert(":(");});



        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        var userSplit = userName.split('|');