suitescript 1.0代码如下:
function clientFieldChanged(type, name, linenum) {
if (name == 'class') {
var brand_id = nlapiGetFieldValue('class');
if (brand_id) {
console.log(brand_id);
var itemSearch = nlapiLoadSearch(null,'customsearch_item_brand_search');
var itemSearchFilter = new nlobjSearchFilter('custitem30', null, 'anyof',brand_id);
var filters = [itemSearchFilter];
itemSearch.setFilters(filters);
itemSearch.saveSearch();
}
}
} 但是执行此脚本后,保存的搜索的过滤器为空。SuiteScript 1.0 saved Search
suitescript 2.0代码如下:
function fieldChanged(scriptContext) {
if(scriptContext.fieldId == 'class'){
var currentRecord = scriptContext.currentRecord;
var brand_id = currentRecord.getValue({fieldId:'class'});
if(brand_id){
var itemSearch = search.load({
id: 'customsearch_item_brand_search'
});
var itemSearchFilter = search.createFilter({
name:'custitem30',
operator:search.Operator.ANYOF,
values:brand_id
});
var filtersArray = [itemSearchFilter];
itemSearch.filters = filtersArray;
itemSearch.save();
}
}
}
执行此脚本后,保存的搜索的过滤器将正确。SuiteScript 2.0 saved Search
如何使SuiteScript 1.0保存的搜索与SuiteScript 2.0保存的搜索相同?
顺便说一句,nlapiRefreshLineItems是Suitescript 1.0的api,但是在2.0版本中没有等效的API。如果我只想在Suitescript 2.0中刷新项目,怎么办?
答案 0 :(得分:0)
在1.0代码中,将setFilters()
更改为addFilters()
,因此您的代码应为:
function clientFieldChanged(type, name, linenum) {
if (name == 'class') {
var brand_id = nlapiGetFieldValue('class');
if (brand_id) {
console.log(brand_id);
var itemSearch = nlapiLoadSearch(null,'customsearch_item_brand_search');
var itemSearchFilter = new nlobjSearchFilter('custitem30', null, 'anyof',brand_id);
var filters = [itemSearchFilter];
itemSearch.addFilters(filters);
itemSearch.saveSearch();
}
}
}
这对我有用,而setFilters
却出错了。
答案 1 :(得分:0)
为什么不呢?
应该可以。