如何在 SuiteScript 中构建套件项目的组件列表?

问题描述 投票:0回答:1

我有一个变量,其结构如下(或者在打印精美后结构如下)。我们称之为 kitRecord。

{
  "id": "11212",
  "type": "kititem",
  "isDynamic": false,
  "fields": {
    "custitem_item_validation_required_on_c": "F",
    "type": "item",
    "id": "11212",
    ...
    "haschildren": "F",
    "vendormapchange": "F"
  },
  "sublists": {
    "recmachcustrecord_item": {
      "currentline": {
        "custrecord_estore_stock_value": "",
        "custrecord_item": "11212",
        "custrecord_process_inv_adj": "F",
        "id": "",
        ...
        "#": "1"
      }
    },
    "sitecategory": {
      "currentline": {
        "category": "",
        ...
        "#": "1"
      }
    },
    "member": {
      "currentline": {
        "dropshipmember": "",
        "item": "",
        "linenumber": "",
        ...
        "#": "3"
      },
      "line 1": {
        "dropshipmember": "F",
        "item": "3848",
        ...
        "sitemtype": "InvtPart",
        "sys_id": "7975557957776222",
        "sys_parentid": "7975557957776222",
        "taxschedule": "3",
        "weight": "11.023115"
      },
      "line 2": {
        "dropshipmember": "F",
        "item": "6034",
        ...
        "sitemtype": "InvtPart",
        "sys_id": "7955851117326628",
        "sys_parentid": "7955851117326628",
        "taxschedule": "3",
        "weight": "63.934067"
      }
    },
    "price5": {
      "line 1": {
        "currency": "5",
        ...
        "pricelevelname": "Base Price",
      },
      "line 2": {
        "currency": "5",
        ...
        "pricelevelname": "Base Price",
      },
      "line 3": {
        "currency": "5",
        ...
        "pricelevelname": "Base Price",           
      },
      ...
    },
    "presentationitem": {
      "currentline": {
        "baseprice": "",
        "description": "",
        "item": "",
        "itemtype": "",
        ...
        "#": "1"
      }
    },
    ...
  }
}

我希望为所有实际行(即除“currentline”之外的所有行)创建一个列表,其中包含套件中每个组件的 id(“member”子列表中元素“item”的值)。让它在 NetSuite 中运行有很多困难。目前有以下代码片段,但没有 bueno (调试日志表明 kitRecord.sublists 没有返回任何内容)。我也尝试过使用 JSON.parse(kitRecord) 但收到语法错误(“JSON 中位置 0 处出现意外的标记 [at JSON.parse (native)”)。对 SuiteScript 来说相当新,因此非常感谢任何指针/资源。

var kitRecordSublists = kitRecord.sublists;
var components = [];
for (var component in kitRecordSublists.member) {
  if (kitRecordSublists.member.hasOwnProperty(component)) {
    var memberLine = kitRecord.sublists.member[component];
    var componentId = memberLine.item;
    components.push(componentId);
  }
}

javascript json netsuite suitescript suitescript2.0
1个回答
0
投票

var kitRecord = record.load({ type: record.Type.KIT_ITEM, id: itemId });
var componentCount = kitRecord.getLineCount({ sublistId: 'member' });
for (var line = 0; line < componentCount; line++) {
  var componentId = kitRecord.getSublistValue({
    sublistId: 'member',
    fieldId: 'item',
    line: line
  });
  var componentRecord = record.load({ type: record.Type.INVENTORY_ITEM, id: componentId });

等等

© www.soinside.com 2019 - 2024. All rights reserved.