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

var barcode = $feature.BARCODE;
if (barcode == null)  // Preserve original MATERIAL value if BARECODE is null
  return $feature.MATERIAL;
  
var materialCode = mid(barcode,9,1);

if (materialCode == 'A') return 'PE2406';
if (materialCode == 'B') return 'PE2708';
if (materialCode == 'C') return 'PE3408';
if (materialCode == 'D') return 'PE3608';
if (materialCode == 'E') return 'PE3708';
if (materialCode == 'F') return 'PE3710';
if (materialCode == 'G') return 'PE4608';
if (materialCode == 'H') return 'PE4710';
if (materialCode == 'J') return 'PVC';
if (materialCode == 'K') return 'PA11';
if (materialCode == 'L') return 'PA12';
if (materialCode == 'M') return 'Steel';
if (materialCode == 'N') return 'Stainless Steel';
if (materialCode == 'O') return 'Cast Iron';
if (materialCode == 'P') return 'Copper';
if (materialCode == 'Q') return 'Brass';
if (materialCode == 'R') return 'Malleable Iron';
if (materialCode == 'S') return 'Ductile Iron';
if (materialCode == 'T') return 'Reinforced Epoxy Resin';
if (materialCode == 'U') return 'Nylon';
if (materialCode == 'V') return 'Glass Filler Nylon';
if (materialCode == '0') return 'Grade A';
if (materialCode == '1') return 'Grade B';
if (materialCode == '2') return 'Grade C';
if (materialCode == '3') return 'Grade X42';
if (materialCode == '4') return 'Grade X46';
if (materialCode == '5') return 'Grade X52';
if (materialCode == '6') return 'Grade X56';
if (materialCode == '7') return 'Grade X60';
if (materialCode == '8') return 'Grade X65';
if (materialCode == '9') return 'Grade X70';
if (materialCode == 'X') return 'Other';

return "No domain value for: " + materialCode;