gpt4 book ai didi

javascript - 如何通过 Suitescript 2.0 在保存的搜索中应用多个过滤器?

转载 作者:行者123 更新时间:2023-12-02 22:43:35 24 4
gpt4 key购买 nike

我正在现有保存的搜索中应用过滤器,但它没有被应用。谁能帮我解决这个问题,因为我是 Suitescripts 的新手?

过滤器:genderitem 正在参数中从 Suitelet 传递到此计划脚本:

var slfilters = runtime.getCurrentScript().getParameter({ name: 'custscript_searchfilter_report' });
  //
// ─── MAIN FUNCTION───────────────────────────────────────────────────
//
function generateReport() {
var slfilters = runtime.getCurrentScript().getParameter({
name: 'custscript_searchfilter_report'
});
log.debug('slfilters', slfilters);

if (!!slfilters) {
slfilters = JSON.parse(slfilters);
}
log.debug('slfilters2', slfilters);

//var getUser = runtime.getCurrentUser();

var gender = slfilters.isgender
log.debug('gender', gender)
var item = slfilters.isItem
log.debug('item', item)

var item = getItems(item, gender);
log.debug('items table', item)
// return item;

var xmlTemplateFile = file.load(3918);
//var template = script.getParameter({ name: 'custscript_template' });
var renderer = render.create();
renderer.templateContent = xmlTemplateFile.getContents();
var customSources = {
alias: 'searchdata',
format: render.DataSource.JSON,
data: JSON.stringify({
value: item,
})
};
renderer.addCustomDataSource(customSources);

var xml = renderer.renderAsString();
var pdf = render.xmlToPdf({
"xmlString": xml
});

email.send({
author: 317,
recipients: 'aniswtf@gmail.com',
subject: 'Item Report',
body: 'Report Generated: ',
attachments: [pdf]
});
}

//
// ─── SEARCH ───────────────────────────────────────────────────
//
function getItems(item, gender) {
try {
var itemSearch = search.load({
id: 'customsearch_mx_itemsearch'
});
log.error('itemSearch', itemSearch)

var defaultFilters = itemSearch.filters;
var arrFilters = [];

arrFilters.push(search.createFilter({
name: 'custitem5', //gender
operator: 'anyof',
values: gender
}));

arrFilters.push(search.createFilter({
name: 'itemid',
operator: 'anyof',
values: item
}));

defaultFilters = defaultFilters.concat(arrFilters);
log.error('Updated Filters', defaultFilters)

var results = itemSearch.run().getRange({
start: 0,
end: 150
});

results.map(function(x) {
return {
'category': x.getText({
name: "custitem10",
join: "parent"
}),
'season': x.getValue({
name: "custitem11",
join: "parent"
}),
'riselabel': x.getValue({
name: "custitem_itemriselabel",
join: "parent"
}),
'fit': x.getValue({
name: "custitem9",
join: "parent"
}),
'name': x.getValue({ //sku
name: "itemid",
join: "parent"
}),
'style': x.getValue({
name: "custitem8",
join: "parent"
}),
'inseam': x.getValue({
name: "custitem7",
join: "parent"
}),
'wash': x.getValue({
name: "custitem_washname",
join: "parent"
}),
};
});
return results;
} catch (e) {
log.error('error in getItems', e)
}
}
return {
execute: execute
};
});

最佳答案

在 SuiteScript 1.0 中,有一个 nlobjSearch 方法“setFilters”。 SuiteScript 2.0 似乎没有等效项,但您仍然需要以某种方式设置过滤器。看来这是缺少的一步。也许尝试将新过滤器推送到/代替当前搜索过滤器

itemSearch.filters.push(defaultFilters);

不确定是否需要保存搜索。我希望这有帮助

关于javascript - 如何通过 Suitescript 2.0 在保存的搜索中应用多个过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58503008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com