Hello,
I'm trying to get the following arcade expression to work. Essentially the app is designed to scan bins, however sometimes the wrong bin gets scanned so I'm trying to implement a validation check so that only certain bin prefixes are allowed to be scanned and submitting but I'm getting the following message when I use this expression
boolean: false
the console also throws out
Failed: Empty or non-text
Result: false
// barcode variable from feature attribute
var barcodeValue = 'BTR7981006';
Console('Barcode Value: ' + barcodeValue);
// Define valid prefixes for Bin
var validPrefixes = [
'BTR75', 'BTR76', 'BTR780', 'BTR781', 'BTR7820', 'BTR7821', 'BTR7831',
'BTR7846', 'BTR7847', 'BTR7848', 'BTR7855', 'BTR7866', 'BTR789', 'BTR790',
'BTR792', 'BTR798'
];
var isValid = false;
// Check if barcode is empty or not a text value
if (IsEmpty(barcodeValue) || TypeOf(barcodeValue) != 'Text') {
Console('Failed: Empty or non-text');
isValid = false;
}
// Check if barcode starts with BTR and is 10 characters long
else if (Left(barcodeValue, 3) != 'BTR' || Length(barcodeValue) != 10) {
Console('Failed: Invalid format, BTR=' + Left(barcodeValue, 3) + ', Length=' + Text(Length(barcodeValue)));
isValid = false;
}
// Check if barcode starts with any valid prefix
else {
for (var prefixIndex in validPrefixes) {
var currentPrefix = validPrefixes[prefixIndex];
if (Left(barcodeValue, Length(currentPrefix)) == currentPrefix) {
Console('Passed: Matched prefix ' + currentPrefix);
isValid = true;
break;
}
}
}
// Return validation result
Console('Result: ' + Text(isValid));
return isValid;