Barcode Generator Bind

The following barcode types can be generated with the 'Barcode generator' bind:

  • one-dimensional: EAN, ITF, or UPC

  • two-dimensional: QR code

Images are generated completely in STEP (for security, no external services are used), and each generated image is saved as the specified asset object type (for example, using an object type of 'barcode').

To make the barcode available for use with a product, additional setup is required to create a reference from the barcode asset to the applicable product. Depending on your experience with JavaScript, you may implement this additional setup via JavaScript, otherwise, use standard functionality available in STEP.

Configuration

To use any bind:

  1. Create a business rule as defined in the Creating a Business Rule, Function, or Library topic.

  2. Edit the business rule as defined in the Editing a Business Rule or Function topic.

  3. In the Edit Operation dialog, add the bind to a business rule, as defined in the Adding a Bind topic in the Resource Materials online help documentation.

  4. In the Edit Operation dialog, optionally add Messages, as defined in the Localized Messages for JavaScript Business Rules topic.

  5. In the Edit Operation dialog, add JavaScript to call the bind.

Barcodes Methods

This bind works with the following methods:

  • generateBarcodeByCodeLength​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

  • generateEAN128​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

  • generateEAN13​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

  • generateEAN8​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

  • generateITF14​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

  • generateQRcode​(Asset asset, java.lang.String qrCodeText, int size, int margin, int errorCorrectionLevel)

  • generateUPC12​(Asset asset, java.lang.String code, int height, int marginHorizontal, int marginVertical)

For more information about these methods, click the Technical Documentation button on the Start Page, and within the Scripting API section, review the Javadoc via one of the links. Search for the Barcodes class.

For more information on the types of barcodes, search the web.

Considerations

The following items should be reviewed to limit issues with generated barcodes:

  • For one-dimensional barcodes, the width is automatically calculated based on the number of characters / bars. Adjust the setting as needed to allow sufficient space between the bars for successful scanning.

  • The Filename parameter on the generated asset is automatically set to show the barcode type and the related data. If the related data includes invalid characters, using the Filename value can result in an error. During export, use the asset ID instead of the Filename to eliminate an issue with invalid filename characters.

  • Running the JavaScript on an asset overwrites any existing code. Creating a revision of a code asset with revision tracking (via the Status tab of the asset editor) can be used to access more than one version of a generated code. Refer to the Revisions topic in the System Setup documentation here.

  • To generate a different code on the same asset, for example per country or language, the asset must be context dependent.

Examples

The following JavaScript examples use the related bind(s).

Important: Example scripts should not be used as-is without thorough testing, including updating the script to match object and link types that exist on your system. JavaScript variable names are case-sensitive.

UPC Code Example

This example generates a UPC code (755359484628) and saves it as the current object, which is a 'barcode' asset object type. The code supplied must be valid.

As shown below, the parameters on the Execute JavaScript business rule 'Edit Operation' dialog set the overall height of the image to 100 pixels, the horizontal margin to 25 pixels, and the vertical margin to 15 pixels.

QR Code Example

This example generates a QR code and saves it as the current object, which is a 'barcode' asset object type. The code generated can be used to access the specified website (URL).

As shown below, the parameters on the Execute JavaScript business rule 'Edit Operation' dialog set the height and width of the image to 100 pixels, the size of the margin to 25 pixels. The quality of the code is set to 3 to allow for successful reading of a slightly damaged code (1 is the lowest quality and 4 is the highest).