gpt4 book ai didi

c# - NetSuite SuiteTalk "customSearchJoin"从 SOAP XML 响应访问

转载 作者:数据小太阳 更新时间:2023-10-29 02:44:23 28 4
gpt4 key购买 nike

我仍在熟悉 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);
}
}

最佳答案

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

}
}
}

关于c# - NetSuite SuiteTalk "customSearchJoin"从 SOAP XML 响应访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34881273/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com