Using scripts in Tasks

You can use scripts in Tasks. Tasks can be started either manually or automatically when the program starts. Tasks can perform specific actions, such as printing, or display dialog boxes, such as scanning barcodes and then printing labels for the items found.

Scan barcode and print labels for found products

Let's assume you have data loaded. You need to scan barcodes and automatically print labels for found products.


Add a task.


Use the following script.

const cMsg_001 = 'Scan barcode or enter manually and press [Enter]. Click Cancel to exit.';
const cMsg_002 = 'No item found with barcode "%s".';

function processInput() {

    // Show a dialog box for entering/scanning a barcode
    let bc = azureLabel.showInput('', '', cMsg_001, false, false, false);
	if (bc === operationCanceledByUser) {
		return false;

    // Looking for an entry with this barcode
    let finded = false;
	const loadedDataCount = loadedData.count();
    for (let i = 0; i < loadedDataCount; i++) {

        if (loadedData.getFieldValue(i, barcodeFieldName) === bc){
	        finded = true;

    // No entry with this barcode found
    if (!finded) {
        azureLabel.showMessage('', azureLabel.format(cMsg_002, bc), 0, 0, 0, 2);
        return true;

    // Print labels
    try {
        azureLabel.printLabels( recordsToPrint, -1, '', '', true, showPreview);
	catch (error) {
        azureLabel.showMessage('', error.toString(), 0, 0, 0, 2);
    return true;

// Show label preview
const showPreview = false;

// The AzureLabel library is required to use the special ListOfRecords class
const ext = require('azurelabel_ext');
// Create a list of records to be passed to the label printing function
const recordsToPrint = new ext.ListOfRecords;
// Create a list of records to store data from Label Printing Data
const loadedData = new ext.ListOfRecords;
// Loading data from Label Printing Data into the list

// Name of the field with barcodes for program versions <= 12.27
let barcodeFieldName = 'Barcode';
let operationCanceledByUser = '';
try {
	// If the program version is > 12.27
	// Find the name of the field with the attribute 'This is a barcode field'
	barcodeFieldName = loadedData.getBarcodeFieldName(0);
	operationCanceledByUser = 'OperationCanceledByUser';
catch (error) {

// Cycle of receiving barcode and printing labels
while (processInput());

Start the task.

After running the task, you will see a dialog box for scanning barcodes.