Retaining Leading Zeros in Number Values
How to Retain Leading Zeros in Barcode Values
The issue you're encountering occurs because the number 0123456
is being treated as an Integer. In integers, leading zeros are automatically removed. However, barcodes often need to retain leading zeros, which requires us to format the number as a String. A string is a sequence of alphanumeric characters, and it can begin with a zero.
To resolve this issue, we need to reformat the data from the source database and ensure it's treated as a string value. Here’s how to do that:
Open the Card Designer:
Go to the Configuration ribbon menu.
Open the Card Designer to edit your card layout.
Edit the Barcode Object:
Double-click the barcode object to open its properties.
Set the Format to String:
In the barcode properties, locate the Format drop-down option.
Change the format from Integer (or any other setting) to String. This step converts the numeric value into an alphanumeric value, which should retain the leading zero.
Using Variables and Script Object for Formatting
If the barcode value is sourced from a database column, you can use Variables to link the column value and ensure it is treated as a string. The Barcode variable could represent the database column containing the barcode number.
To apply Python formatting and make sure leading zeros are retained, you’ll need to use the Script Object in the card design:
Select the Script Object:
In the Standard Object Type drop-down menu, select Script.
Enter your Python script in the text field below. For example:
str(Barcode)
to ensure the value is treated as a string.int(Barcode)
if you want to convert it to an integer (though this will remove leading zeros).
The Script Object allows you to apply custom logic to the data, like converting the barcode value into a string format. This will make sure any leading zeros are kept.
Note: Scripting is only available in the Business Edition and Enterprise Edition of the software.