Skip to end of metadata
Go to start of metadata

Description

Here is a discussion of creating a script that changes a field's text from any case to upper case.

Prerequisites

Label 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)

  1. var - This is short for Variable.  Used in this context you are setting a variable.
  2. 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.
  3. = - Operator equating the variable to something else, the variable is then used to substitute the parameters.
  4. ((label.fields.field.(@name == 'Description').@data)) - These are the parameters that will now be referenced by the variable. 
  5. ((label.fields.field. - In this case we are looking on the current label, and then in the category of fields.
  6. (@name == 'Description') - And here we identify the actual field, named Description. 
  7. .@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.
  8. ; - ends the current string.

Setting a new variable (performing the function)

  1. var UpperCase= - We are setting a new variable named Uppercase.
  2. LowerCase. - This is calling back the data that we set in the first variable, in this case the data from the field Description.
  3. .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.).
  4. ; - ends the current string.

Creating the output (placing the changed data on the label)

  1. 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.
  2. .@data=UpperCase (mailto:.@data=UpperCase) - This calls the data which we pulled from the label, and modified and places it back on the label.
  3. ; - ends the current string.

Notes

  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.

Article Number

 2011014

Versions

 Loftware Print Server Version 9.5.2.0 and up

Environment

All supported installation environments.