Search code examples
c#web-servicessoapnetsuitesuitetalk

NetSuite Transaction Search Returned Without Any Line Items for Invoice


I am attempting to import an invoice from NetSuite into my program. In this program, I need as much information about the invoice as possible to be returned. However it does not appear that any of the line item information is being returned. Here is my piece of code I am completing for the search. Any suggestions? I am trying to complete this with as few calls out to NetSuite as possible in order to keep performance high.

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);
}

Solution

  • I found my answer in the "Suite Talk Web Services Platform Guide":

    SuiteTalkWebServicesPlatformGuid_2012.1.pdf (Page 34, Setting Search Preferences.)

    I have included my solution and code below in case the guide become unavailable at a future date.

    bodyFieldsOnly
    boolean
    Defaults to TRUE and indicates that the information in the body fields of the record are returned — significantly improving performance. Any fields in associated lists or sublists are not returned. If the bodyFieldsOnly field is set to FALSE, all fields associated with the record are returned.

    So I was missing setting my bodyFieldsOnly to false. Once it was set to false then I was getting back the full information desired.

    /// <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;
    }