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;
Solved! Go to Solution.
There are a few things that need to be fixed in your code.
// 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) != 'String') {
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' || Count(barcodeValue) != 10) {
Console('Failed: Invalid format, BTR=' + Left(barcodeValue, 3) + ', Length=' + Text(Count(barcodeValue)));
isValid = false;
}
// Check if barcode starts with any valid prefix
else {
for (var prefixIndex in validPrefixes) {
var currentPrefix = validPrefixes[prefixIndex];
if (Left(barcodeValue, Count(currentPrefix)) == currentPrefix) {
Console('Passed: Matched prefix ' + currentPrefix);
isValid = true;
break;
}
}
}
// Return validation result
Console('Result: ' + Text(isValid));
return isValid;
There are a few things that need to be fixed in your code.
// 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) != 'String') {
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' || Count(barcodeValue) != 10) {
Console('Failed: Invalid format, BTR=' + Left(barcodeValue, 3) + ', Length=' + Text(Count(barcodeValue)));
isValid = false;
}
// Check if barcode starts with any valid prefix
else {
for (var prefixIndex in validPrefixes) {
var currentPrefix = validPrefixes[prefixIndex];
if (Left(barcodeValue, Count(currentPrefix)) == currentPrefix) {
Console('Passed: Matched prefix ' + currentPrefix);
isValid = true;
break;
}
}
}
// Return validation result
Console('Result: ' + Text(isValid));
return isValid;
Thank you so much! I was pulling my hair out wondering what was wrong.
I understand why you changed the script to string instead of text as text isnt truly an acceptable field type that ESRI uses.
However how did you also know length was not the right function to use?