3

我正在尝试从 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);
}
4

2 回答 2

6

我在“Suite Talk Web Services Platform Guide”中找到了我的答案:

SuiteTalkWebServicesPlatformGuid_2012.1.pdf(第 34 页,设置搜索首选项。)

我在下面包含了我的解决方案和代码,以防该指南在将来变得不可用。

bodyFieldsOnly
boolean
默认为 TRUE,表示返回记录正文字段中的信息 — 显着提高性能。不返回关联列表或子列表中的任何字段。如果 bodyFieldsOnly 字段设置为 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;
}
于 2013-09-03T20:33:56.257 回答
0

感谢这个惊人而有用的注释,特别是转向 (_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
于 2019-03-05T17:17:56.793 回答