Skip to end of metadata
Go to start of metadata


Basics of how to develop field level scripts for Loftware labels.

How to create field level scripts


  1. First define your variables. To make things easier you can use the same variable name as the corresponding field on the label where applicable.
    • var – This is short for Variable. Used in the context you are setting a variable.
    • Variable names are case sensitive (i.e. fieldname is not the same as fieldName).
    • Variables can not have spaces. Use underscores.
    • You can set the value of your variable in this step as well.
    • You can also set variable with no value to be determined by the data manipulation process of the script.

  2. Next define the values being pulled from the label if not previously defined.
    • Using the command <variablename> = String(label.fields.field.(@name == '<field name>').@data);
    • @name – defines the field name being used from the label
    • @data – defines the string as the characters from the field
    • There are other @ "attributes" that can be used based on the type of field

  3. Create if/then statements, concatenations, formulas, font changes, etc. and other data manipulation. When creating your statements you can use the variable defined in steps.
    • When performing mathematical operations java script will attempt to define the variables based on context.
    • In the example below the statement: cutoff = (current_year * 1) + 1 has to have the * operator to define the current_year variable as a numeric value. If current_year is 09 the result is 10.
    • If you did not include the * operator (cutoff = current_year + 1) the script treats current_year as a string and you would get 091 as the result since + can be used as addition or concatenate.

  4. Finally define what will be sent back to fields on the label to print.
    • Using the command: label.fields.field.(@name=='<field name>').@data = <variablename>;


  1. The script does not need to be contained in the field where the output ends up. By default the field in which the script runs is non-printing unless, like above, we create output to that field.
  2. Only one script can be run on a label, but the script can have multiple sections, using various fields, and various outputs.
  3. Formulas on labels will run first, and the script is run last. We can use any output from a field with a formula in a script, however, we cannot use the output of the script in a formula. We can perform formula functions in a script.
  4. While not necessary it sometimes makes it easier to trouble shoot a script with the //comments. This is especially helpful if the script is large and complex.
  5. When you have the Scripting Data Source window open and click OK or Verify Script the Design32 program will run a low level check against the code and identify syntax and format errors. It does NOT check the functionality of the code. Note: java script IS case sensitive (i.e. If is not the same as if)

Script Example

(Associated 'date script label.lwl' label in the attachments section)

// define variables
var two_digit_year;
var new_date;
var cutoff;
var prefix;
var complete_date;
var current_year
// define data to be pulled from label
two_digit_year = String(label.fields.field.(@name == 'two_digit_year').@data);
new_date = String (label.fields.field.(@name == 'new_date').@data);
current_year = String(label.fields.field.(@name == 'current_year').@data);
cutoff = (current_year * 1) + 1;
// if statment
if (two_digit_year > cutoff)
prefix = "19";
} else {
prefix = "20";
// end if
//concatenate 2 fields
complete_date = prefix.concat(new_date);
//define values to output to label for printing
label.fields.field.(@name == 'prefix').@data = prefix;
label.fields.field.(@name == 'complete_date').@data = complete_date;

Refer to the Loftware LLM User Guide for additional information on using label scripts.

Article Number



Loftware version and up


Any supported LPS family product environment