0

Barcode validation script

Hi,

There is my script to check barcodes checksum. It calculates check digit for the following list of standarts at once: GTIN-8 (EAN-8), GTIN-12 (UPC), GTIN-13 (EAN-13), GTIN-14, GSIN and SSCC.

let barcodeShrinked := replace(barcode, " ", "");
let barcodeLength := length(barcodeShrinked);
let evenPositionDigitSum := 0;
let oddPositionDigitSum := 0;
if barcodeLength = 8 or barcodeLength = 12 or barcodeLength = 13 or barcodeLength = 14 or barcodeLength = 17 or barcodeLength = 18 then
let barcode := lpad(barcodeShrinked, 19, "0");
for i in range(0, 9) do
evenPositionDigitSum := evenPositionDigitSum + number(substr(barcode, i * 2, 1));
oddPositionDigitSum := oddPositionDigitSum + number(substr(barcode, i * 2 + 1, 1))
end;
let barcodeCheckSum := number(substr(barcode, 18, 1));
let resultSum := 3 * oddPositionDigitSum + evenPositionDigitSum;
let resultCheckSum := 0;
if resultSum != 10 * floor(resultSum / 10) then
resultCheckSum := 10 * floor(resultSum / 10) - resultSum + 10
else
void
end;
if barcodeCheckSum != resultCheckSum then
barcode_validation_message := "Wrong checksum"
else
barcode := barcodeShrinked;
barcode_validation_message := "Correct"
end
else
barcode_validation_message := "Wrong barcode"
end

This script runs each time I update "barcode" field. For comfort editing reason script understands optional spaces between digits — it will cut them off if the barcode is valid.

Unfortunately I didn't find the way to change field's background color, so I added an additional field "barcode_validation_message" to indicate out whether data in main field is correct or wrong.

Barcode Validation in Ninox

1 reply

null
    • Jorg
    • 5 yrs ago
    • Reported - view

    Hi, 

    Thank you for your script.

    To have colours for fields is already added in our list of requested features. We hope to release it in one of our upcoming versions. 
    At the moment it is possible to set a colour for a field with the styled() function in a function field.

    styled(text, colour, icon) 
    - creates styled text elements. The icon is placed to the left of the text. Use "" for none, and the colour is the objects background

    e.g.:  styled("Attention", "red", "warn")

    Best, Jörg

Content aside

  • 5 yrs agoLast active
  • 1Replies
  • 1693Views