我正在尝试将NetSuite的发票导入我的程序。在这个程序中,我需要尽可能多的关于发票的信息才能被退回。但是,似乎没有返回任何订单项信息。这是我为搜索完成的代码。有什么建议?我想尽可能少地打电话给NetSuite,以保持高性能。
SearchResult searchResults = new SearchResult();
TransactionSearch ts = new TransactionSearch();
TransactionSearchBasic tsb = new TransactionSearchBasic();
// Search for Invoices
if (_InvoiceTxnIds.Count > 0)
{
tsb.internalId = new SearchMultiSelectField();
tsb.internalId.@operator = SearchMultiSelectFieldOperator.anyOf;
tsb.internalId.operatorSpecified = true;
List<RecordRef> rrlist = new List<RecordRef>();
foreach (string sTxnId in _InvoiceTxnIds)
{
RecordRef rr = new RecordRef();
rr.internalId = sTxnId;
rrlist.Add(rr);
}
tsb.internalId.searchValue = rrlist.ToArray();
ts.basic = tsb;
searchResults = _service.search(ts);
}
答案 0 :(得分:5)
我在“Suite Talk Web服务平台指南”中找到了答案:
SuiteTalkWebServicesPlatformGuid_2012.1.pdf(第34页,设置搜索首选项。)
我已在下面提供了我的解决方案和代码,以防指南在将来无法使用。
bodyFieldsOnly
布尔值默认为TRUE和 表示记录正文字段中的信息 返回 - 显着提高性能。中的任何字段 不返回关联的列表或子列表。如果bodyFieldsOnly field设置为FALSE,与记录关联的所有字段都是 返回。
所以我错过了将bodyFieldsOnly设置为false。一旦它被设定 如果我错了那么我就得到了所需的全部信息。
/// <summary>
/// <p>This function builds the Pereferences and SearchPreferences in the SOAP header. </p>
/// </summary>
private void setPreferences()
{
// Set up request level preferences as a SOAP header
_prefs = new Preferences();
_service.preferences = _prefs;
_searchPreferences = new SearchPreferences();
_service.searchPreferences = _searchPreferences;
// Preference to ask NS to treat all warnings as errors
_prefs.warningAsErrorSpecified = true;
_prefs.warningAsError = false;
_searchPreferences.pageSize = _pageSize;
_searchPreferences.pageSizeSpecified = true;
// Setting this bodyFieldsOnly to true for faster search times on Opportunities
_searchPreferences.bodyFieldsOnly = false;
}
答案 1 :(得分:0)
感谢这份令人惊奇且有用的说明,特意将(_searchPreferences.bodyFieldsOnly = False)转为获取商品详细信息
我已修改代码以适合VB(通过发票号获取发票详细信息,谢谢
受保护的子GetInvoiceDetails_Click(作为对象发送,作为EventArgs发送)处理Button12.Click
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
'=========== Setup a service Name
Dim service1 As NetSuiteService = New NetSuiteService()
service1.CookieContainer = New CookieContainer
'============ set application id , you need to set it up prior on Netsuite , Setup-Integration-Manage Integration , then add App name and generate ID
Dim AppInfo = New ApplicationInfo()
AppInfo.applicationId = "ABCDEFGhdjddjdjdjd-theAppID-&66hsdjhfn"
service1.applicationInfo = AppInfo
'========= Setup a passport
Dim passport1 As Passport = New Passport()
passport1.account = "1234567" ' Your Company Account ID with Netsuite
passport1.email = "user@domain.com" 'Your/or user email on Netsuite, you nead to maintain the role related, for example in this give Invoice-View, Transaction Search-View too
Dim role As RecordRef = New RecordRef()
role.internalId = "3" ' 3 for admin , netsuite will active the 2 factor Auth soon , so use any role than Admin , and replace this ID
passport1.role = role
passport1.password = "Your Password on Netsuite"
'==== log in
Dim Status As Status = service1.login(passport1).status
'---- you can put the result in Textbox to see the result and steps too , or writeline works too
TextBox1.Text = Status.isSuccess.ToString
'==========
TextBox1.Text = TextBox1.Text & " =================" & Environment.NewLine
Dim _InvoiceTxnIds(2) As String ' put the invoice Numbers in Array , or you can make a loop too , in this example it will search for 3 Invoice#80,#81 and #82 details
_InvoiceTxnIds(0) = "80"
_InvoiceTxnIds(1) = "81"
_InvoiceTxnIds(2) = "82"
Dim SearchResult1 As SearchResult = New SearchResult()
Dim Ts As TransactionSearch = New TransactionSearch()
Dim TsBasic As TransactionSearchBasic = New TransactionSearchBasic()
TsBasic.internalId = New SearchMultiSelectField()
TsBasic.internalId.operator = SearchMultiSelectFieldOperator.anyOf
TsBasic.internalId.operatorSpecified = True
Dim Rrlist As List(Of RecordRef) = New List(Of RecordRef)()
For Each sTxnId As String In _InvoiceTxnIds
Dim rr As RecordRef = New RecordRef()
rr.internalId = sTxnId
Rrlist.Add(rr)
Next
'------ put search preferences
Dim _prefs As Preferences = New Preferences()
_prefs.warningAsErrorSpecified = True
_prefs.warningAsError = False
service1.preferences = _prefs
Dim _searchPreferences As SearchPreferences = New SearchPreferences()
'_searchPreferences.pageSize = _pageSize
_searchPreferences.pageSizeSpecified = True
_searchPreferences.bodyFieldsOnly = False ' important to make it false to let Netsuite return back the invoice item details
service1.searchPreferences = _searchPreferences
'============
service1.searchPreferences.bodyFieldsOnly = False
TsBasic.internalId.searchValue = Rrlist.ToArray()
Ts.basic = TsBasic
Dim res As SearchResult = service1.search(Ts)
TextBox1.Text = TextBox1.Text & " res.status.isSuccess value : " & res.status.isSuccess & Environment.NewLine
If res.status.isSuccess Then
Dim recordList As Record()
TextBox1.Text = TextBox1.Text & " res.totalPages : " & res.totalPages & Environment.NewLine
For i As Integer = 1 To res.totalPages
recordList = res.recordList
TextBox1.Text = TextBox1.Text & " recordList Lenghth #: " & recordList.Length & Environment.NewLine
For j As Integer = 0 To recordList.Length - 1
If TypeOf recordList(j) Is Invoice Then
Dim Inv As Invoice = CType((recordList(j)), Invoice)
TextBox1.Text = TextBox1.Text & " invoice #: " & Inv.tranId & Environment.NewLine
TextBox1.Text = TextBox1.Text & "Total amount: " & Inv.total & Environment.NewLine
If Inv.itemList IsNot Nothing Then
TextBox1.Text = TextBox1.Text & " invoice items list Qty #: " & Inv.itemList.ToString & Environment.NewLine
For k = 0 To Inv.itemList.item.Length - 1
Dim item As InvoiceItem = CType((Inv.itemList.item(k)), InvoiceItem)
TextBox1.Text = TextBox1.Text & " Item Name:" & item.item.name & ", quantity: " & item.quantity & Environment.NewLine
' you can use the other values too like prices, amount, cost ....ETC
Next
TextBox1.Text = TextBox1.Text & "Total amount: " & Inv.total & Environment.NewLine
End If
End If
Next
Next
Else
TextBox1.Text = TextBox1.Text & " Error:" & res.status.ToString & " ----" & Environment.NewLine
End If
End Sub