1
votes

I am making an app in java that uses Netsuite's SuiteTalk web services to create a report. I defined a transaction saved search in which I use as a criteria the date and I print in the results the default Transaction columns plus the Department external ID and the sum of the amount. I run the saved search via UI and I get what I am expecting, however, when I try to get the information in my java code I keep getting null results. I have tried the java versions of the following solutions:

C# NetSuite WebServices: Get value from custom field in saved search (ItemSearchAdvanced)

http://www.anyforum.in/question/web-service/netsuite/How-to-get-data-from-saved-search-through-webservice-request/345

However, none of this has worked for me. When I go to the Lists->Search->Saved Searches menu on my Netsuite UI, I am able to see my saved search when I set in the filters "General" and "Transaction". However, I haven't been able to retrieve it's information via API.

This is the code that I use to try to get the saved search data:

public void printReport() throws ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault, ExceededRecordCountFault, RemoteException, UnsupportedEncodingException, SOAPException{

        //METHOD 1: Transaction Search
        TransactionSearchAdvanced sr = new TransactionSearchAdvanced();
        //"customsearchreport" is the IF of my saved search
        sr.setSavedSearchId("customsearchreport");
        SearchResult res = _port.search(sr);
        System.out.println(res.getTotalRecords());

        //METHOD 2: Item search

        ItemSearchAdvanced isa = new ItemSearchAdvanced();
        isa.setSavedSearchId("customsearchreport");
        SearchResult resp = _port.search(isa);
        System.out.println(resp.getTotalRecords());

        //METHOD 3: General saved search 

        GetSavedSearchRecord gssr= new GetSavedSearchRecord();
        //I set the record type as "transaction" as I created a transaction saved search.
        gssr.setSearchType(SearchRecordType.transaction);
        GetSavedSearchResult gssre = _port.getSavedSearch(gssr);
        System.out.println("Saved Search status: "+ gssre.getStatus().isIsSuccess());
        RecordRefList srl = gssre.getRecordRefList();
        RecordRef[] rr = srl.getRecordRef();
        System.out.println("RecordRef[] size: " + rr.length);
        for (int i = 0; i < rr.length; i++) {
            RecordRef rref = rr[i];
            System.out.println("External ID: " + rref.getExternalId());
            System.out.println("Internal ID: "+ rref.getInternalId());
            System.out.println("Name: "+ rref.getName());
        }


    }

With METHODS 1 and 2, I am not able to obtain results (I print "null"). The third method prints me 16 saved searches, however, none of the printed searches correspond to the ones I have created. When I check the saved search list through the UI, I see that there exist 21 non private saved searches and 4 have been created by me. From the 16 reports that are printed, one corresponds to a private saved search.

So, I don't get why I can't get my saved search result and what determines if a report is accessible through any method. Any help to obtain my savedSearch throough the API would be appreciated. Also, could any one explain how Netsuite determines which saved searches appear through any "get" method?

Thanks!

2
What does res.getStatus() return?Klitos Kyriacou
res.getStatus() returns true, as the search was executed successfully.Diego Serrano
That's strange, because whenever I get res.getStatus().isIsSuccess() == true, then res.getTotalRecords() always returns me a valid Integer object (even if it's 0), not null.Klitos Kyriacou
That's correct. I got null objects when I tried to iterate over the records. Sorry for the inconvenience.Diego Serrano

2 Answers

2
votes

I solved it. The ID "customsearchreport" I was using is a UI ID. I had to use the InternalID for my report. Also, I was able to print my saved search IDs with the getSavedSearch() method by selecting the "All company members" checkbox in my the "Audience" section of my saved search.

0
votes

I solved them

Before the second script, we must increase the number pages limit like this:

SearchPreferences sp = new SearchPreferences();
                sp.pageSize = 1000;
                _service.searchPreferences = sp;

                SubsidiarySearch subsidiarySrch = new SubsidiarySearch();
                SearchResult srchResult = _service.search(subsidiarySrch);