How do we solve the issue of showing ‘The minimum quantity for this item’ error when we try to return an item from the website?

When we buy an items with a minimum quantity and try to return a non-minimum quantity item in the return section of the website, we might face this error. We can use this solution to solve this error.

SuiteScript:

// JJ.Return.Authorization.js
// Load all your starter dependencies in backend for your extension here
// ----------------

define('JJ.Return.Authorization'
,	[
		'ReturnAuthorization.Model',
		'Application',
		'underscore'
	]
,	function (
	ReturnAuthorizationModel, Application, _
	)
{
	'use strict';
	_.extend(ReturnAuthorizationModel, {
		// @method create
		// @param data
		// @return {Number}
		//create function is extending for storing the newfield values in Return form of NetSuite.
		create: function (data) {
			const returnAuthorization = nlapiTransformRecord(
					data.type,
					data.id,
					'returnauthorization'
			);
			const CURRENT_LINE = this.getTransactionLines(data.id);
			this.setLines(returnAuthorization, data.lines, CURRENT_LINE);
			returnAuthorization.setFieldValue('memo', data.comments);
			_.each(data.lines, function (line, key) {
				returnAuthorization.setLineItemValue('item', 'custcol_jj_returns_item_used', key + 1, line.custcol_jj_returns_item_used);
				returnAuthorization.setLineItemValue('item', 'custcol_jj_returns_item_damaged', key + 1, line.custcol_jj_returns_item_damaged);
				returnAuthorization.setLineItemValue('item', 'custcol_jj_returns_item_inpackage', key + 1, line.custcol_jj_returns_item_inpackage);
			});
			for (var i = 1; i <= returnAuthorization.getLineItemCount('item'); i++) {
				if (returnAuthorization.getLineItemValue('item', 'quantity', i) < 1) {
					returnAuthorization.removeLineItem('item', i);
				}
			}
			return nlapiSubmitRecord(returnAuthorization);
		},
	})
});

Leave a comment

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