我在Suitelet中具有以下SuiteScript 2.0代码,我想在其中将其他过滤器添加到已加载的已保存搜索中(库存项目子列表和库存调整记录的主记录):
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);
但是,代码在行rs.filters = defaultFilters;
上继续失败,并显示以下错误:
{"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}
我尝试使用request.parameters.custscript_report_context.toString()
而不是981, "981", ["981"]
,但是没有运气。
custscript_report_context
是整数类型,在尝试通过N\record
加载记录时效果很好。
我将保存的搜索中的internalid
作为列返回。
有人知道我在做什么错吗?
答案 0 :(得分:3)
您不能在 searchFilters 中推送数组,而只能过滤对象。如果使用 filter-expressions ,则需要数组。
尝试以下代码
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);
答案 1 :(得分:0)
类似于其他答案...虽然您不能像@Avi的答案中所述那样推送数组,但是可以像这样连接这些数组,而无需遍历它们。只是为了说明这个概念而已:
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;
}
注意:这是我从其他post / answer收集的内容的编辑版本。