Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Description

The following is an example of a string replacement script developed to allow the passing of a FNC1() character in a .pas or .xml data file. This concept can be applied to other scenarios where character sequences in the data from the input file is not allowed.

How to use a label script to replace a string or character

The following procedure replaces a string or character with another string or character using a label script. This also allows passing of data that is normally not allowed in an .xml file format. 

  1. Set up a scripting field, input field, and a fixed field containing a formula with the replacement character ('FNC1 ()' as shown in the following example).
  2. Copy the sample script below into a text editor.
  3. Modify the sample script, using the names of the actual fields on your label.
  4. Copy the modified script into the scripting field data source window. 

For an example, refer to the attached sample label fnc1 replace.lwl.

Sample Script
//Script allows customer to pass FNC1() character as data for barcode using proxy [FNC1].  Can be modified to allow any formula function character.
var input = String(label.fields.field.(@name == 'input_barcode').@data);
var fnc1 = String(label.fields.field.(@name == 'F1').@data);
 
var strReplaceAll = input;
var intIndexOfMatch = strReplaceAll.indexOf( "[FNC1]" );
 
// Loop over the string value replacing out each matching substring.
while (intIndexOfMatch != -1)
     {
     // Relace out the current instance.
     strReplaceAll = strReplaceAll.replace( "[FNC1]", fnc1 )
     
     // Get the index of any next matching substring.
     intIndexOfMatch = strReplaceAll.indexOf( "[FNC1]" );
     }
label.fields.field.(@name == 'input_barcode').@data = strReplaceAll;

Article Number

2017102

Versions

LLM 9.5.2.0 and later

Environment

Any supported LPS Family product environment

  • No labels