I have a variable that is structured like below (or is structured like below once pretty-printed). Let's call it 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"
}
},
...
}
}
I am looking to create a list with the id of each component in the kit (value for element 'item' in the 'member' sublist) for all real lines (that is, all lines excluding 'currentline'). Having a lot of difficulties getting this to work in NetSuite. Currently have the below snippet but no bueno (debug log suggests that kitRecord.sublists is returning nothing). I've also tried utilising JSON.parse(kitRecord) but receive a syntax error ("Unexpected token s in JSON at position 0 [at JSON.parse (native)"). Fairly new to SuiteScript, so any pointers/resources are greatly appreciated.
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);
}
}
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 });
etc