-
StackOverflow 文件
-
netsuite 教程
-
使用子列表
-
2.0 標準模式下的子列表
// Working with a sublist in Standard Mode in SuiteScript 2.0...
require(["N/record"], function (r) {
var rec = r.create({
"type": r.Type.SALES_ORDER,
"isDynamic": false
});
// Set relevant body fields ...
// Add line item 456 with quantity 10 at the beginning of the Items sublist
rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 456, "line": 0});
rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 10, "line": 0});
// Insert line item 238 with quantity 5 at the beginning of the Items sublist
rec.insertLine({"sublistId": "item", "line": 0});
rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 238, "line": 0});
rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 5, "line": 0});
// Insert line item 777 with quantity 3 before the last line of the Items sublist
var lastIndex = rec.getLineCount({"sublistId": "item"}) - 1; // 2.0 sublists have 0-based index
rec.insertLine({"sublistId": "item", "line": lastIndex}); // The last line will now actually be at lastIndex + 1
rec.setSublistValue({"sublistId": "item", "fieldId": "item", "value": 777, "line": lastIndex});
rec.setSublistValue({"sublistId": "item", "fieldId": "quantity", "value": 3, "line": lastIndex});
// Remove the first line
rec.removeLine({"sublistId": "item", "line": 0});
// Remove the last line
rec.removeLine({"sublistId": "item", "line": rec.getLineCount({"sublistId": "item"}) - 1});
rec.save();
});