首页 > 解决方案 > 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.

标签: suitescript2.0

解决方案


在 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
})


推荐阅读