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:
<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.
<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:
<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.
<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>
Article Number
2014007
Versions
Loftware Label
A label is a design area on the computer screen where a label format is created or edited. Manager / Loftware Print Server versions 9.5.2.0 - 11.1
Environment
All supported installation environments.