suitescript2.0 - Looping Through a Group in Suitescript 2.0
问题描述
I am passing sales orders grouped by item into a function. I need to load the sales orders to modify the sales order record that it has already been processed. How would I go about getting all sales orders grouped under the item?
var itemId = result.getValue({
name: 'item',
summary: 'GROUP'
});
The above code gets me the item id for what the orders in the given result are being grouped by. There could be any number of sales within a single group.
解决方案
在 SuiteScript 中运行分组保存的搜索并不能让您像在用户界面中运行类似搜索时那样“向下钻取”。只要您在保存的搜索中为任何列设置了汇总标准,Netsuite 就会要求汇总您的所有列。如果您想获取销售订单的内部 ID,则必须将它们作为已保存搜索代码中的汇总列返回。
像这样的东西:
const searchObj = search.create({
type: search.Type.SALES_ORDER,
filters: [
['mainline', 'is', 'F']
//,'AND', any other filters you need...
],
columns: [
search.createColumn({
name: "item",
summary: "GROUP"
}),
search.createColumn({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
})
]
}).run().each(function(result) {
const itemId = result.getValue({name: "item", summary: "GROUP"})
const salesOrderIds = result.getValue({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
}).split(',')
return true
})
推荐阅读
- r - 如何使用 Shiny 实现基本统计?tapply 中的错误:参数必须具有相同的长度”
- ios - 有没有办法在 iOS 中标记文件,这样它们就不会在存储空间不足的情况下从 Library/Caches 目录中清除
- python - 如何使用 tf.cond?
- node.js - Vue js:从生产版本最小化文件中提取实际代码
- reactjs - 样式未在 React Native 中应用
- scala - 如何在 Breeze 中为 SparseVector 的每个元素添加一个?
- javascript - 数组内的javascript承诺
- php - 在 Symfony 中使用 Ajax 访问控制器方法
- html - Bootrstap 4底部导航栏无法删除左右边距
- node.js - 复杂的 NodeJS / Express REGEX 路由