Update Inventory Detail in SuiteScript

Update an Inventory Detail subrecord on an existing transaction through SuiteScript.

When updating the Inventory Detail using client scripts, the method setCurrentSublistSubrecord throws the error: “NOT_SUPPORTED_ON_CURRENT_SUBRECORD”.

Setting Subrecord values is currently not supported in client scripts since the subrecord object in this context is only available in view-mode.

The solution is to update the Inventory Details through a Suitelet Script instead.

Sample Suitelet that updates the quantity of the first line item of a credit memo:

/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */

define(["N/record"], function (record) {‌
    function onRequest(context) {‌

		var recordType = record.Type.CREDIT_MEMO;
		var recordId = 123


		var recObj = record.load({‌
			type: 'creditmemo',
			id: recordId
		});

		// Update quantity for list item (to avoid quantity mismatch error)
		recObj.setSublistValue({‌
			sublistId: 'inventorydetail',
			fieldId: 'quantity',
			line: 0,
			value: 2
		});

		// Load subrecord
		var subrec = recObj.getSublistSubrecord({‌
		  sublistId: 'item',
		  fieldId: 'inventorydetail',
		  line: 0
		});

		if(subrec){‌
			// Update quantity for subrecord. Note quantity total must equal quantity in item line
			subrec.setSublistValue({‌
				sublistId: 'inventoryassignment',
				fieldId: 'quantity',
				line: 0,
				value: 2
			});
		}

		recObj.save();
    }
    return {‌
        onRequest: onRequest
    };
});

Leave a comment

Your email address will not be published. Required fields are marked *