Scripting Basics
Description
Here is a discussion of creating a script that changes a field's text from any case to upper case.
Prerequisites
Label
A label is a design area on the computer screen where a label format is created or edited. with the following fields, Description (keyboard entry), Corrected (script):
var LowerCase= ((label.fields.field.(@name == 'Description').@data));
var UpperCase= LowerCase.toUpperCase();
label.fields.field.(@name == 'Corrected').@data=UpperCase;
What does this mean?
This example demonstrates pulling data from one field, modifying it, and placing it back on the label.
Details
Setting a variable (pulling in data from the label)
- var - This is short for Variable. Used in this context you are setting a variable.
- LowerCase - Is the name of the variable being set, you can name this whatever you want and should be something you will remember, and be relevant to what you are doing.
- = - Operator equating the variable to something else, the variable is then used to substitute the parameters.
- ((label.fields.field.(@name == 'Description').@data)) - These are the parameters that will now be referenced by the variable.
- ((label.fields.field. - In this case we are looking on the current label, and then in the category of fields.
- (@name == 'Description') - And here we identify the actual field, named Description.
- .@data) (mailto:.@data))) Now that we have selected the field, we can perform several functions on the field, here we are pulling in the data from the field.
- ; - ends the current string.
Setting a new variable (performing the function)
- var UpperCase= - We are setting a new variable named Uppercase.
- LowerCase. - This is calling back the data that we set in the first variable, in this case the data from the field Description.
- .toUpperCase()- This is a Java function (Spider Monkey Java) that will take data and change the case of all text to uppercase, regardless of it's current case, while not changing non-alpha characters (numbers, symbols, etc.).
- ; - ends the current string.
Creating the output (placing the changed data on the label)
- label.fields.field.(@name == 'Corrected') - Here we are defining where the data is going to end up on the label. In this case a field on the label called Corrected.
- .@data=UpperCase (mailto:.@data=UpperCase) - This calls the data which we pulled from the label, and modified and places it back on the label.
- ; - ends the current string.
Notes
- 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.
- Only one script can be run on a label, but the script can have multiple sections, using various fields, and various outputs.
- 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.
-
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.
Article Number
2011014
Versions
Loftware Label Manager / Loftware Print Server versions 9.5.2.0 - 11.1
Environment
All supported installation environments.