Requirement:
Restrict customers to buy quantity more than the available quantity.If the user tries to add the quantity more than the available one,then the value should be updated to the available value of an item.
Solution:
Update the client script that applies to ‘sales order’.And if the user adds value greater than the available value,then the value in the cart will be updated to maximum available quantity.
var response = nlapiRequestURL(fullUrl, null, headers, "GET");
var body = JSON.parse(response.getBody());
var code = response.getCode();
var quantityavailable = body.items[0].quantityavailable
nlapiLogExecution('DEBUG', 'quantityavailable', quantityavailable);
var quantity = nlapiGetCurrentLineItemValue('item', 'quantity');
if(quantity > quantityavailable){
nlapiLogExecution('DEBUG', 'inside if condition');
nlapiSetCurrentLineItemValue('item', 'quantity', quantityavailable);
nlapiLogExecution('DEBUG', 'changed quantity', quantity);
}