Hello everyone,
I'm trying to create a SuiteScript client script that checks if the bin number field is empty on an item receipt transaction. If the bin number field is empty, I want to display an error message and prevent the user from saving the transaction. If the bin number field is not empty, the transaction should be allowed to save as normal.
I've created the script, but I'm having issues with it not allowing the transaction to save even when the bin number field is entered.
Here's my script:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/ui/dialog'],
function(dialog) {
function saveRecord(context) {
var currentRecord = context.currentRecord;
var itemCount = currentRecord.getLineCount({sublistId: 'item'});
var hasEmptyBin = false;
for (var i = 0; i < itemCount; i++) {
var binNumber = currentRecord.getSublistValue({
sublistId: 'item',
fieldId: 'binnumber',
line: i
});
if (!binNumber) { // Checking if bin number field is empty
hasEmptyBin = true;
break;
}
}
if (hasEmptyBin) { // If any bin number field is empty, show an error message and prevent saving the record
dialog.alert({
title: 'Error',
message: 'Please enter a value for bin number field.'
});
return false;
} else { // If all bin number fields are not empty, allow saving the record
return true;
}
}
return {
saveRecord: saveRecord
};
});
Any help or suggestions would be greatly appreciated. Thank you!