suitescript2.0inventorysaved-searches

suitescript 2.0 unable to search inventorydetails subrecord from saved search data


I have created one saved search, and I am fetching data from by suitescript and here is the demo data response which I am getting this result from saved search response

{
    "results": [
        {
            "recordType": "itemreceipt",
            "id": "2572118",
            "values": {
                "trandate": "2021-3-25",
                "type": [
                    {
                        "value": "ItemRcpt",
                        "text": "Item Receipt"
                    }
                ],
                "tranid": "RCV123",
                "salesrep": [
                    {
                        "value": "16018",
                        "text": "MXZ"
                    }
                ],
                "entity": [
                    {
                        "value": "16993",
                        "text": "ABC"
                    }
                ],
                "memo": "",
                "amount": "1218.00",
                "location": [
                    {
                        "value": "1",
                        "text": "XYZ"
                    }
                ],
                "inventoryDetail.inventorynumber": [
                    {
                        "value": "10504",
                        "text": "3566044578"
                    }
                ]
            }
        }
]
}

AND I AM USING BELOW CODE TO MAKE FILTER BY inventoryDetail.inventorynumber FIELD WHICH IT MENTIONED IN SAVED SEARCH RESPONSE DATA AND IT THROWS ERROR "An nlobjSearchFilter contains invalid search criteria: inventoryDetail.issueinventorynumber."

but if I used tranid instead of inventoryDetail.issueinventorynumber then it does not throw the error, why I can not filter by inventoryDetail.inventorynumber I am trying since two days but no luck, please help me guys

/**
* @NApiVersion 2.1
* @NScriptType Restlet
* @NModuleScope Public
*/

/* 

------------------------------------------------------------------------------------------
Script Information
------------------------------------------------------------------------------------------

Name:
Saved Search API

ID:
_saved_search_api


*/


var 
     log,
     search,
     response = new Object();     


define( [ 'N/log', 'N/search' ], main );


function main( logModule, searchModule ) {

     log = logModule;
     search = searchModule;

    return { post: postProcess }

}


function postProcess( request ) {     
     
     try {
        var searchObj = search.load( { id: 1234 } );//saved search id

// Copy the filters from rs into defaultFilters.
var defaultFilters = searchObj.filters;

// below code works 
defaultFilters.push(search.createFilter({
  name: "tranid",
  operator: search.Operator.IS,
  values: ["RCV123"]
}));
// but this code does not works and it throws error "An nlobjSearchFilter contains invalid search criteria: inventoryDetail.issueinventorynumber."
/*defaultFilters.push(search.createFilter({
  name: "inventoryDetail.inventorynumber",
  operator: search.Operator.IS,
  values: ["3566044578"]
}));*/
searchObj.filters = defaultFilters;
       
    searchObj.filters = defaultFilters;
          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 ) ;
                response.count =results.length; 
          } while ( results.length );          
                                             
          return response;
                    
     } catch( e ) {     
          log.debug( { 'title': 'error', 'details': e } );
          return { 'error': { 'type': e.type, 'name': e.name, 'message': e.message } }
     }     
          
}

Solution

  • Finally I found the solution

    var transactionSearchObj = search.create({
       type: "transaction",
       filters:
       [
         ["formulatext: {inventorydetail.inventorynumber}","contains","30124578547"]
       ],
       columns:
       [
          search.createColumn({name: "trandate", label: "Date"}),
          search.createColumn({name: "type", label: "Type"}),
          search.createColumn({name: "tranid", label: "Document Number"}),
          search.createColumn({name: "salesrep", label: "Sales Rep"}),
          search.createColumn({name: "memo", label: "Memo"}),
          search.createColumn({name: "amount", label: "Amount"}),
          search.createColumn({name: "location", label: "Location"}),
         search.createColumn({
             name: "itemid",
             join: "item",
             label: "Name"
          }),
          search.createColumn({
             name: "inventorynumber",
             join: "inventoryDetail",
             label: " Number"
          })
       ]
    });
    return transactionSearchObj.run().getRange( { start: 0, end: 0 + 1000 } );