Hi Guys, So, i've been trying to retrieve a saved...
# suitescript
w
Hi Guys, So, i've been trying to retrieve a saved search report using a suitescript as explained in the following blog: https://timdietrich.me/blog/netsuite-saved-search-api/ but i get this error once i send an API request: { "error": { "type": "error.SuiteScriptError", "name": "UNABLE_TO_DETERMINE_RECORD_TYPE_FOR_SAVED_SEARCH_ID_1", "message": "Unable to determine record type for saved search id 638" } } anyone who has faced such before? or rather how can i solve this??
n
Typically happens when you are searching on a custom record. But essentially inside your RESTlet you are trying to load the search with search.load({id: request.searchId}) This search.load call also takes another parameter called type. In situations where the netsuite api can’t determine the search type (like you have here) you have to specify it in the search.load. So my recommendation would be to update your RESTlet to say
search.load({id: request.searchId, type: request.searchType})
Then in your request payload you send to the RESTlet, add in the search type parameter.
w
Hi @Nathan L, Thank you soo much for this, • so for my request payload i should specify "SavedSearch" type parameter right? that's what i'm getting from the docs
n
Yeah so assuming you are using the cURL request body from the article your new request should look something like this
Copy code
curl -X "POST" "<https://tstdrv2355109.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=899&deploy=1>" \
     -H 'Content-Type: application/json' \
     -H 'Authorization: OAuth oauth_consumer_key="7d2c8326a648d4ac7e3013bb492a4a77570677ac2bdba24b30cc24d3dfae722e", oauth_nonce="U8mgCkrNJa5evQdh7ARaoxERtE2beDVr", oauth_signature="Ao4sydHcRTXMPqhzkv8k%2B12NS%2FbzicaqX1js02UlrSM%3D", oauth_signature_method="HMAC-SHA256", oauth_timestamp="1633340518", oauth_token="029e4df8d69a6ad6313e732cd59dccbd430096e4d6c3ed773c24e2ff6321a842", oauth_version="1.0", realm=TSTDRV2355109' \
     -H 'Cookie: NS_ROUTING_VERSION=LAGGING' \
     -d $'{
  "searchID": "customsearch_esc_my_customers_2",
  "searchType": "some_record_type_here"
}'
Then your restlet should look something like this
Copy code
function postProcess( request ) {     
     
     try {
     
          if ( ( typeof request.searchID == 'undefined' ) || ( request.searchID === null ) || ( request.searchID == '' ) ) {          
               throw { 'type': 'error.SavedSearchAPIError', 'name': 'INVALID_REQUEST', 'message': 'No searchID was specified.' }               
          }     
          
          // here is where we updated the code to match the new payload
          var searchObj = search.load( { id: request.searchID, type: request.searchType } );

          response.results = [];

          var resultSet = searchObj.run();

          var start = 0;

          var results = [];

          do {
     
               results = resultSet.getRange( { start: start, end: start + 1000 } );
          
               start += 1000;
          
               response.results = response.results.concat( results ) ;
          
          } while ( results.length );          
                                             
          return response;
                    
     } catch( e ) {     
          log.debug( { 'title': 'error', 'details': e } );
          return { 'error': { 'type': e.type, 'name': e.name, 'message': e.message } }
     }     
          
}
w
that's in order... my saved search type is a report reading from a customized financial statement, what search type value should i use here?
r
If native: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4483165708.html If custom: Customization > Lists, Records, & Fields > Record Types. The ID is what you want.
n
https://chrome.google.com/webstore/detail/netsuite-search-export/gglbgdfbkaelbjpjkiepdmfaihdokglp Additionally there is this really cool plugin that you can add to chrome that will let you view the suitescript for any saved search you have. just go into edit mode of a saved search and in the top right of the page, there will be a button to view
It will also show you the type of search that is running
b
the error is telling you that it netsuite doesnt know what type of search to run (a little ridiculous but thats what we are stuck with)
netsuite 1
💯 1
you need to find the search in the ui, determine its type, then put the script id of the search into the type parameter
w
what if the searchType is a report?
b
then you are doomed
😂 2
doommad 1
suitescript doesnt support reports
w
For real🤣🤣
any alternative that you'd suggest?
n
Try to rebuild it as a saved search 🤷
Or an analytics workbook
👍 1