ליאור גבסו
12/26/2024, 1:57 PMCeligo AI
12/26/2024, 1:57 PMAI generated answer (using internal Slack threads):To prevent inventory transfer from a location with Quantity On Hand 0, you can create a SuiteScript that checks the quantity on hand before allowing the transfer. Here's a simple example of how you could do this:
javascript
define(['N/record', 'N/runtime'], function(record, runtime) {
function beforeSubmit(context) {
if (context.type !== context.UserEventType.CREATE) return;
var newRecord = context.newRecord;
var sublistLineCount = newRecord.getLineCount({sublistId: 'inventory'});
for (var i = 0; i < sublistLineCount; i++) {
var quantity = newRecord.getSublistValue({
sublistId: 'inventory',
fieldId: 'quantity',
line: i
});
var location = newRecord.getSublistValue({
sublistId: 'inventory',
fieldId: 'location',
line: i
});
var item = newRecord.getSublistValue({
sublistId: 'inventory',
fieldId: 'item',
line: i
});
var itemRecord = record.load({
type: record.Type.INVENTORY_ITEM,
id: item
});
var locationLine = itemRecord.findSublistLineWithValue({
sublistId: 'locations',
fieldId: 'location',
value: location
});
var quantityOnHand = itemRecord.getSublistValue({
sublistId: 'locations',
fieldId: 'quantityonhand',
line: locationLine
});
if (quantity > quantityOnHand) {
throw new Error('Cannot transfer more than quantity on hand');
}
}
}
return {
beforeSubmit: beforeSubmit
};
});
This script will throw an error and prevent the record from being saved if the quantity being transferred is greater than the quantity on hand at the specified location. You can deploy this script on the Inventory Transfer record type.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
12/26/2024, 1:58 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842063308
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838213086
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83491087
Celigo AI
12/26/2024, 1:58 PM