Create a Script To Define a Printing Field Property

Description

Create a field level script that prints (or does not print) a field based on the value of a key field. This is useful if you need to create a label with conditional fields or images that are dependent on the value of other fields on the label.
The effect of this type of script is to turn on or off the printing attribute of a field on the label.

Solution

Use the Example Label

This example uses the FieldLevelScript.lwl file attached to this article.
There are three fields on the label:

Copy
Example Script
<pre class="syntaxhighlighter-pre" xml:space="preserve">//define variables 
var input1 = String(label.fields.field.(@name == 'Print_Value').@data);

//define if-else statement 
if (input1=="P" || input1=="p" || input1=="print" || input1=="PRINT" || input1=="true")  
{
   //print field
   label.fields.field.(@name =='Print_Field').@printingField = true;   
}
else  
{
   //don't print field
   label.fields.field.(@name =='Print_Field').@printingField = false; 
} </pre>

  1. Save the example label to the Loftware Labeling/Labels folder or to your custom Labels folder.
  2. Open the label with Design32.
  3. Using On-Demand Print or File DropClosed The action of making print requests by placing files in the LPS scan directory. LPS detects this request and responds by printing the label. See Scan Directory., pass p, P, Print, PRINT or true to the Print_Value field. The Print_Field text should appear on the label.
  4. Print again, but pass a "false" value to Print_Value. The text will not appear, as the Print_Field has become a non-printing field.

Create a Label with a Field Level Script

  1. Create a new label, and add the following fields:
    • A scripting field
    • An input field
    • A field that will print or not print
  2. Modify the example script using the names of the fields on your label.
  3. Copy the modified script into the scripting field data source window (Loftware recommends creating scripts in a text editor such as Notepad and copying into the Data Source window).