Retrieving Null Field Values ​​from a Saved Search in Netsuite

I created a saved search in Netsuite. I am trying to get field values ​​through a webservice call from my application. I am getting the full size of the records correctly, but when trying to get the field values, I am getting null for all fields (like filename) from my saved search. Here is the code:

TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
tsa.setSavedSearchId("825");
SearchResult result = _port.search(tsa);
System.out.println("size of recds..." + result.getTotalRecords());

if (result.getTotalRecords() > 0) {
    // retain the search ID in order to get more pages 
    String sSearchId = result.getSearchId();
    SearchRowList rowList = result.getSearchRowList();
    processRowList(rowList);
    int iNumPages = result.getTotalPages();
    System.out.println("pages" + iNumPages);
    for (int i = 2; i <= iNumPages; i++) {
        result = _port.searchMoreWithId(sSearchId, i);
        rowList = result.getSearchRowList();
        System.out.println("jjjj" + rowList);
        processRowList(rowList);
    }
}

_port.logout();

public void processRowList(SearchRowList rowList) {
    try {
        System.out.println("inside process...." + rowList);
        for (int i = 0; i < rowList.getSearchRow().length; i++) {
            TransactionSearchRow ts = (TransactionSearchRow) rowList.getSearchRow(i);
            TransactionSearchRowBasic tsb = ts.getBasic();
            SearchColumnSelectField[] scsf = tsb.getItem();
            for (SearchColumnSelectField sf: scsf) {
                RecordRef rf = sf.getSearchValue();
                System.out.println("itemname:::" + rf.getName());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

      

+3


source to share


2 answers


I am new to Netsuite, but I was desperate to solve the same problem and I think I have an answer. I think that when you are trying to print out the names of the elements, you are trying to iterate over all the possible fields that the string can have. However, this "item" object that contains the TransactionSearchRowBasic is not a list of items that this object can contain. Then you should try to get the values ​​that contain your saved transactions.

So, let's say I have a transaction-saved search where I want to show the transaction period, type, account, amount, date, and external ID of the corresponding department. First, I looked at this link for the API id of each entry versus its UI name:

https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/transaction.html

Then I used very similar Java code as yours, but with some fixes.

This method checks that everything is in order and calls the method that actually prints the data fields:

public void printTransactionRowFields() throws ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault, ExceededRecordCountFault, RemoteException, UnsupportedEncodingException, SOAPException
    {
        TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
        //This is my Transaction saved search Internal ID
        String savedSearchID = "999";
        tsa.setSavedSearchId(savedSearchID);

        SearchResult srr = _port.search(tsa);
        boolean isSuccess = srr.getStatus().isIsSuccess();
        System.out.println("Search result: "+ isSuccess);
        int searchNumRecords = srr.getTotalRecords();
        System.out.println("Amount of records: "+ searchNumRecords);
        if (isSuccess) 
        {
            if(searchNumRecords > 0)
            {
                int iNumPages = srr.getTotalPages();
                //Must check the amount of pages to process every record
                System.out.println("Num pages: "+ iNumPages);
                //Must retain search ID to search for more pages. This is a web service ID, it not the same as the internal ID "999"
                String sSearchID = srr.getSearchId();
                System.out.println("Search id: "  + sSearchID);
                SearchRowList rowList = srr.getSearchRowList();
                System.out.println("Num rows in row list 1: " +rowList.getSearchRow().length);
                processReportRowList(rowList);
                //We process the next iNumPages pages (it not 0 index)
                for ( int i=2; i<=iNumPages; i++) {
                    //Users who authenticate to NetSuite by providing their credentials in the SOAP header of
                    //their requests must use searchMoreWithId to retrieve search results that span multiple pages.
                    //They cannot use searchMore or searchNext, since both operations require an active session.
                    //(For information on request-level-credential authentication, see Request-Level Credentials.)
                    srr = _port.searchMoreWithId(sSearchID, i);
                    rowList = srr.getSearchRowList();
                    System.out.println("Num rows in row list #" +i+": " +rowList.getSearchRow().length);
                    processReportRowList(rowList);
                } 
            }else{
                System.out.println("This saved search contains no records to process.");
            }
        }
        else{
            System.out.println("Search could not find Transaction Saved Search with id: " + savedSearchID);
        }
    }

      



This method handles printing of transaction period, type, account, quantity, date, department fields.

public void processReportRowList(SearchRowList rowList) 
    {
        if(rowList!= null){
            System.out.println("Search row length: " + rowList.getSearchRow().length);
            for (int i=0; i<rowList.getSearchRow().length; i++) {
                TransactionSearchRow row=(TransactionSearchRow)rowList.getSearchRow(i); 
                TransactionSearchRowBasic basic= row.getBasic();
                System.out.println((basic==null)?"Basic is Null.":"Basic is not null.");
                RecordRef period = basic.getPostingPeriod(0).getSearchValue();
                String periodInternal = period.getInternalId();
                String  type = basic.getType(0).getSearchValue();
                RecordRef account = basic.getAccount(0).getSearchValue();
                Double amount = basic.getAmount(0).getSearchValue();
                Double amountFC = basic.getFxAmount(0).getSearchValue();
                Calendar tranDate = basic.getTranDate(0).getSearchValue();
                DepartmentSearchRowBasic deparmentRow = row.getDepartmentJoin();
                String departmentExternalID = deparmentRow.getExternalId(0).getSearchValue().getInternalId();
                //Print results
                System.out.println("Row# "+i+"\n"+"Period Internal ID: "+periodInternal +"\n Type: "+ type+ "\n Account Internal ID: "+
                accountInternal + "\n Amount: "+ amount + "Foreign Currency Amount: "+ amountFC + "\n Date: " + tranDate.getTime().toString()+
                "\n Department External ID: "+departmentExternalID);
            }

        }else{
            System.out.println("Row list arrived null");
        }
    }

      

Note that I had to create a DepartmentSearchRowBasic as I am trying to get the external department ID from a department record. In my saved search, I selected this external department ID with the option "Department Fields ...".

If you are lost on which method above your TransactionSearchRowBasic object will return you the correct field that you selected in the saved search result, you can use Eclipse's debug mode to find out which fields are not null and which types they return and contain.

Hope this answer helps all people to deal with the lack of good Netsuite documentation! (Although, this is just my opinion)

+1


source


Here's an example that searches and completes the results and assigns the name of the child to a variable (entry = auxiliary, field name = name). The variable value is reassigned with each occurrence of the loop and for illustration purposes only.

I think you were looking for the getFieldValue function .



Council . Use the NetSuite Records Browser and Schema Browser for a valid list of records and columns.

var rec = '';
var subsidiaryName = '';
var searchResults = nlapiSearchRecord( 'subsidiary', null, null, null );
for ( var i = 0; i < Math.min( 100, searchResults.length ); i++)
{
    var record = nlapiLoadRecord(searchResults[i].getRecordType(),searchResults[i].getId() );
    subsidiaryName = record.getFieldValue('name');
}

      

0


source







All Articles