Useful Scripting Functions

Description

This article outlines a few functions that are extremely useful when using the Field Level Scripting in Loftware.

Most of the Loftware commands involving fields on the label require the use of a long string.

Here is a prime example:

Copy
Getting Data
<pre class="syntaxhighlighter-pre" xml:space="preserve">var x = String(label.fields.field.(@name=='inputField').@data);</pre>

 It is easy to see how someone could easily mistype this lengthy string.

Functions can be cut and pasted into the script to reduce the required typing.

Copy
getData Function
<pre class="syntaxhighlighter-pre" xml:space="preserve">function getData(fieldName)
  {
  return String(label.fields.field.(@name==fieldName).@data);
  }</pre>

As a result, the code to assign the data to a variable is as follows:

Copy
Using getData Function
<pre class="syntaxhighlighter-pre" xml:space="preserve">var x = getData('inputField');</pre>

Functions are best used when a particular command is going to be used multiple times in the script.

How to Implement the Solution

Here are a list of commands and the suggested function.

Copy
Examples
<pre class="syntaxhighlighter-pre" xml:space="preserve">//Getting Data
//common command
var x = String(label.fields.field.(@name=='inputField').@data);
 
//function command
varx = getData('inputField');
 
//function
function getData(fieldname)
  {
  return String(label.fields.field.(@name==fieldName).@data);
  }   
 
 
//Putting Data back on the label
//common command
label.fields.field.(@name=='outputField') = x;
 
//function command
putData('outputField',x);
 
//function
function putData (fieldName,output)
  {
  label.fields.field.(@name==fieldName).@data=output;
  }
 
 </pre>