感谢这个惊人而有用的注释,特别是转向 (_searchPreferences.bodyFieldsOnly = False) 以获取项目详细信息
我已修改代码以适合 VB(通过发票编号获取发票详细信息,谢谢
Protected Sub GetInvoiceDetails_Click(sender As Object, e As 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