NetSuite SuiteScript 2.0 Adding additional filters to a loaded saved search erroring with WRONG_PARAMETER_TYPE

若如初见. 提交于 2020-01-06 18:13:30

问题


I have the following SuiteScript 2.0 code in a Suitelet where I would like to add an additional filter to the loaded saved search (inventory items sublist and main record of the Inventory Adjustment record):

  var rs = s.load({
    id: "customsearch_inv_adj_item_search"
  });

  // Copy the filters from rs into defaultFilters.
  var defaultFilters = rs.filters;
  var customFilters = [
     s.createFilter({
        name: "internalid",
        operator: s.Operator.IS,
        values: request.parameters.custscript_report_context.toString()
     }),
  ];

  // Push the customFilters into defaultFilters.
  defaultFilters.push(customFilters);

  // Copy the modified defaultFilters back into rs
  rs.filters = defaultFilters;

  var results = rs.run().getRange(0, 1000);

However the code keeps on failing on the line rs.filters = defaultFilters; with the error:

{"type":"error.SuiteScriptError","name":"WRONG_PARAMETER_TYPE","message":"Wrong parameter type: filters[2] is expected as Filter. ","stack":["createError(N/error)","onRequest(/SuiteScripts/sui_custom_pdf_report.js:308)","createError(N/error)"],"cause":{"name":"WRONG_PARAMETER_TYPE","message":"Wrong parameter type: filters[2] is expected as Filter. "},"id":"","notifyOff":false,"userFacing":true}

Instead of request.parameters.custscript_report_context.toString() I have tried 981, "981", ["981"] but no luck.

custscript_report_context is of type integer and it works fine in trying to load the record via N\record.

I am returning internalid in my saved search as a column.

Does anyone know what I'm doing wrong?


回答1:


You cannot push an array in searchFilters, only filter objects. Arrays are required if you use filter-expressions.

Try the following code

var rs = s.load({
  id: "customsearch_inv_adj_item_search"
});

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

// Push the customFilters into defaultFilters.

defaultFilters.push(s.createFilter({
  name: "internalid",
  operator: s.Operator.IS,
  values: request.parameters.custscript_report_context.toString()
}));
// Copy the modified defaultFilters back into rs
rs.filters = defaultFilters;

var results = rs.run().getRange(0, 1000);



回答2:


Similar to other answers...while you can't push an array as mentioned in @Avi 's answer, you can concatenate the arrays as such, eliminating the need to loop through them. This is kind of drawn out, just to show the concept:

 var additionalFilters = new Array();;
                 additionalFilters.push(search.createFilter({name: 'account', operator: search.Operator.ANYOF, values: mainArgs.
                 additionalFilters.push(search.createFilter({name: 'postingperiod', operator: search.Operator.IS, values:[mainArgs.param_posting_period]}));

                 var mySearch = search.load({id: searchID});
                 if(additionalFilters){

                     //Copy the filters from mySearch into defaultFilters
                     var defaultFilters = mySearch.filters;

                     //We will add the new filter in customFilters
                     var customFilters = [];
                     customFilters = additionalFilters;

                     //We will concatenate the customFilters and defaultFilters, thereby creating a new array called allFilters
                     var allFilters = defaultFilters.concat(customFilters);

                     //We will assign the allFilters array back into mySearch
                     mySearch.filters = allFilters;

                 }

Note: This is an edited version of what I gleaned from a different post / answer



来源:https://stackoverflow.com/questions/54216699/netsuite-suitescript-2-0-adding-additional-filters-to-a-loaded-saved-search-erro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!