//Script for UPDM 2019 Data Models
//Script to decode and populate the MANUFACTURELOTNO value from the BARCODE value

if ($feature.BARCODE == null)  // Preserve original MANUFACTURELOTNO value if BARCODE is null
   return $feature.MANUFACTURELOTNO;

var barcode = $feature.BARCODE;
var input = mid(barcode,2,4);
var BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

var digit;
var x = 0;
for (digit=1; digit <= count(input); digit++) {
   x = x * count(BASE62) + find(mid(input,digit-1,1),BASE62,0); }

return x