前回の記事「New to NetSuite | Understanding SuiteScript 2.x Modules」では、レコードを操作するために使用されるSuiteScript ModulesおよびN/recordモジュールについて、「New to NetSuite | N/record Module Overview」で説明しました。今回は、N/recordのメンバーの1つであるRecord.cancelLine(options)メソッドを詳しく見ていきます。
***Record.cancelLine(options)は、サブリストの現在の行の編集をキャンセルし、commitLine()で確定されていない変更を破棄します。動的モードでのみ機能し、既存の行は削除しません。Record.cancelLine(options)
構文:
recordObject.cancelLine({
sublistId: 'sublist_internal_id'
});
- 必須オプション: sublistId — 'item'など、サブリストの内部ID。
- 戻り値: 同じrecord.Recordオブジェクト。
- Governance: cancelLine()自体による使用量ユニットの消費はありません。
SuiteScriptの使用例
この例では、受注を読み込み、最初のアイテムの数量を一時的に変更してから、編集をキャンセルします。
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], (record, log) => {
function execute(context) {
// Replace 12345 with an existing sales order internal ID.
const salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: 12345,
isDynamic: true // Required for cancelLine().
});
// Stop if the sales order has no item lines.
if (salesOrder.getLineCount({ sublistId: 'item' }) === 0) {
return;
}
// Read the original quantity. Line indexes start at 0.