The following paragraph does not apply to any country where such provisions are inconsistent with local law:
LEXMARK INTERNATIONAL, INC., PROVIDES THIS PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express
or implied warranties in certain transactions; therefore, this statement may not apply to you.
This publication could include technical inaccuracies or typographical errors. Changes are periodically made to the
information herein; these changes will be incorporated in later editions. Improvements or changes in the products or
the programs described may be made at any time.
Comments about this publication may be addressed to Lexmark International, Inc., Department F95/032-2, 740 West
New Circle Road, Lexington, Kentucky 40550, U.S.A. In the United Kingdom and Eire, send to Lexmark International
Ltd., Marketing and Services Department, Westhorpe House, Westhorpe, Marlow Bucks SL7 3RQ. Lexmark may use
or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you.
You can purchase additional copies of publications related to this product by calling 1-800-553-9727. In the United
Kingdom and Eire, call +44 (0)8704 440 044. In other countries, contact your point of purchase.
References in this publication to products, programs, or services do not imply that the manufacturer intends to make
these available in all countries in which it operates. Any reference to a product, program, or service is not intended to
state or imply that only that product, program, or service may be used. Any functionally equivalent product, program, or
service that does not infringe any existing intellectual property right may be used instead. Evaluation and verification of
operation in conjunction with other products, programs, or services, except those expressly designated by the
manufacturer, are the user’s responsibility.
Lexmark and Lexmark with diamond design are trademarks of Lexmark International, Inc. registered in the United
States and/or other countries.
This software and documentation are provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the
Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and
Computer Software clause at DFARS 252.227-7013 and in applicable FAR provisions: Lexmark International, Inc.,
Lexington, KY 40550.
This book provides a technical reference for LDDScript, the scripting language for the Lexmark
Document Distributor. It is assumed you are already familiar with the language; if not, please review
the "Basic Script Writing" book installed with this product.
If you are migrating from LDD version 1.4, start with Appendix A, "Migrating from LDD 1.4 to 2.1".
The Script Reference is organized as follows:
Chapter 1, "The Basics"—Quick overview of the basic constructs of LDDScript. For detailed
examples, please see the "Basic Script Writing" book.
Chapter 2, "Data Type Objects" — Information on the supported data types.
Chapter 3, "Helper Objects"—Information on the objects that are used to perform common
operations
Chapter 4, "System Objects"—Information on the objects that provide the data provided with a
submitted job and provide feedback to the end-user.
Chapter 5, "Action Objects"—Information on the objects that perform the actual processing of
documents to route, store in a database, print, and so on.
Appendix A, "Migrating from LDD 1.4 to 2.1"—Information for users migrating from previous
versions of LDD.
Appendix B, "LDD Constants Reference"—Quick lookup of all the constants used in LDDScript.
Appendix C, "ODBC Reference"—Information about interfacing with databases from within a script.
Appendix D, "Barcode Reference"—Information about the barcodes supported by LDDScript.
1
What’s new in version 2.1
Lexmark Document Distributor 2.1 has enhanced many of it’s standard features as well as added
some brand new function. Additions and enhancements include:
Actions
•PrintIP—Now supports Staple and Print Confirmation (WaitForCompletion and WaitTimeout
properties)
New actions
•
ImageText Action—Place text anywhere on an image
•Electronic Document Manipulation (EDMS) actions that include third party database software;
SharePoint and Domino.Docs
Document Server Admin
Script Editor improvements that include:
•find/replace—Use the find/replace tool to take you to the code you want
•print—Print a hard copy of your script from the Script Editor
•insert logic—Automatically insert logic syntax into your script
•auto-complete—Automatically finishes your actions
•auto-indent—Automatically indents your script when inserting a sub-routine
Documentation
Expanded documentation including:
•Basic Script Writing—Documentation to help you get started writing your first script
•Script Examples—Detailed script examples (included with LDD) with line–by–line explanations
of the code
•Server Admin Tour—Take a detailed tour of the tools available in your Document Server
Admin
2
1
The Basics
Objects
An object is the basic building block of LDDScript. An object contains properties and methods. A
property is one of the basic data type objects such as a string or integer. A property is set to various
values to affect how the object operates. A method is a function called to operate on the data. A
method may be passed parameters and may return a value. The parameters and return values are
data type or helper objects.
Dot notation is used to access the properties and methods of an object.
•Data Type—The most basic objects; all properties and most variables are of this type.
•Helper—Provide an easy way to perform some common operations.
•System—Do not process documents; used to gather input and provide user feedback.
•Action—Process documents; perform the archiving, routing, distribution, etc.
The remaining chapters in this book provide a reference for objects of each type.
3
Declaring Variables
All variables must be declared before they can be used. Variables cannot be declared inside of a "with"
block or inside of any logic blocks like if/then or loops. To declare a variable, specify its object type and
name. For example:
string text
int num
There are some rules to follow when naming your variables:
•Name must consist of letters, numbers, and underscores.
•The first character of the name must be a letter.
•Must be unique within the script, the names are not case sensitive so "Name", "NAME", and
"name" are all considered the same variable name.
•Cannot be a reserved word (one that has a special meaning to the script compiler).
Flow control
In order to control the execution of script statements, some type of flow control logic is necessary.
Script statements can be executed three ways: sequentially, selectively, or repetitively.
When no flow control logic is used, the statements are executed in the order they are in the script. For
selective execution of certain script statements, you can use if/then/else or switch/case statements.
For repetitive execution of script statements, the loop and repeat statements can be used.
These flow control statements are discussed next.
If/Then/Else
The most common type of flow control is the ability to execute a statement if a certain condition is true.
This ability is implemented in Document Server by the if/then/else construct. The basic format is:
if (bool expression) then
statement1statementn
endif
statement1 to statementn are only executed if the Boolean expression in parentheses is TRUE.
Sometimes it is also necessary to evaluate one set of statements if a condition is TRUE and another if
it is FALSE. That can be accomplished using the else construct:
if (bool expression) then
statementa
statementc
else
statementx
statementz
endif
statementa to statementc are executed if the Boolean expression in parentheses is TRUE;
otherwise, statementx to statementz are executed.
4
Switch/Case
Sometimes you have more than one condition you want to check for. You can do this with several
If/Then statements. The Switch/Case statement provides an easier way to make multiple comparisons:
Integer switchString switch
switch (intvar) switch (stringvar)
case intval1case "stringval1"
statementa statementa
statementb statementb
case intval2case "stringval2"
statementc statementc
statementd statementd
default default
statemente statemente
statementf statementf
endswitch endswitch
You can use integer or string values with the Switch/Case statement. Based on the value of the
variable, the case block corresponding to that value is executed. Each case block can contain multiple
statements but only one case block is executed.
If the value of the switch variable does not match any of the cases, the default block is executed. The
default block is not required. However, if a default block is used, it must be the last block.
Example of Switch
Lexmark MFPs have a job accounting capability. When this feature is enabled, users must enter an
account number before accessing a profile. For this example, users enter a department number when
using profiles. This example script uses a Switch/Case statement to check the department number.
string CustomSubject
// Use the account number as an integer
int DeptNumber = original.useracct.AsInt()
switch (DeptNumber)
case 35
CustomSubject = "Document from Human Resources"
case 41
CustomSubject = "Document from Legal Department"
case 15
CustomSubject = "Document from Shipping Department"
default
CustomSubject = "Document from FooBar Company"
endswitch
Each statement in a script is executed only once. The repeat and loop statements let you execute the
same block of statements multiple times. You can insert an empty repeat or loop statement by clicking
the Insert Logic button on the Script Editor toolbar.
Loop
When you want to repeat a set of statements a known number of times, use the loop statement.
Syntax:
loop (intcounter from istart to ifinish)
statement1
statementn
endloop
where:
•intcounter is a previously declared integer variable
•istart is an integer value to assign to intvar when the loop starts
•ifinish is an integer value that is the maximum for intvar
Using an integer variable as a counter, the loop is repeated as many times as specified in the
istart/ifinish information. You can include as many statements as you want in the loop block.
The loop block ends with the endloop statement.
The loop begins with the counter variable being assigned the value indicated by istart. With each
execution of the loop, the value of the counter is incremented by 1. This continues until the counter is
greater than the value of ifinish.
So a loop from 1 to 10 repeats until the counter has a value of 11. The value of istart must be less
than the value of ifinish.
The integer variable used for the counter must be declared prior to using it in the loop statement.
Example:
E-mail the originally scanned document to ten customer service representatives. In this script, the
common EmailSMTP properties are specified before the e-mails are sent inside the Loop statement.
string EmailAdd
int LoopCount
// Set up the common properties for the emails.
with EmailSMTP
.Subject="Customer Complaint"
.Server="mail.server.com"
.From="customer_service@foobar.com"
.Message="Please review this complaint"
.Attachments=original.document
.CharacterSet=LDD_SMTPCHARSET_US
endwith
loop (LoopCount from 1 to 10)
EmailSMTP.To="CustRep" + LoopCount.AsString() + "@foobar.com"
EmailSMTP.Go()
endloop
6
Repeat
The repeat statement lets you execute a block of statements over and over until an expression
becomes true.
repeat (until bool expression)
statement1
statementn
endrepeat
The repeat statement executes the block of statements until the Boolean expression is TRUE. You
can have as many statements as you want in the loop block. The endrepeat statement ends the loop
block. If the initial value of the Boolean expression is true, the loop is not executed.
Example:
This script uses Optical Character Recognition (OCR), to check documents scanned by end users for
confidential documents. If the document is confidential it is not e-mailed. The scanned image is saved
to a file and a warning message sent to the user who scanned the confidential document.
// Open the results of the OCR Action
tf.Open(ConvertToText.output)
bool bConfDoc = FALSE
int iCount, iEnd
iCount =1
iEnd = tf.GetNumberLines()
Submitter = original.username+ "@lexmark.com"
// Check each line for the term Confidential
repeat (until (bConfDoc OR (iCount>=iEnd)))
OneLine = tf.ReadLine()
if (OneLine.Contains("Confidential"))
then
bConfDoc = TRUE
endif
iCount.Add(1)
endrepeat
7
// If it's a Confidential Document, save it and send warning message
if (bConfDoc)
then
with SaveToFile
.input=original.document
.Path="c:\ebc.txt"
.AppendTimestamp=TRUE
.Overwrite=FALSE
.SaveUserData=FALSE
.Go()
endwith
with EmailSMTP
.Server="mail.server.com"
.To= Submitter
.From="mailcheck@abcxyz.com"
.Subject="Invalid Email Rejected"
.Message="Cannot email a confidential document"
.CharacterSet=LDD_SMTPCHARSET_US
.Go()
endwith
else
with EmailSMTP
.Server="mail.server.com"
.To="Receiver@abcxyz.com"
.From=Submitter
.Subject="Scanned Document"
.Message="Here is the document you requested"
.CharacterSet=LDD_SMTPCHARSET_US
.Attachments=original.document
.Go()
endwith
endif
8
Operators
Mathematical
These operators are used to set or change the value of a variable or property.
OperatorSymbolDescription
Addition+For integer and real objects, this
Subtraction-For integer and real objects, this
Multiplication*For integer and real objects, this
Division\For integer and real objects, this
adds the numbers on both sides of
the "+" and returns the new value.
For string objects, this has a similar
affect as the concatenate method. It
appends the string on the right to
the string on the left and return the
new string. For document objects, it
appends the document on the right
to the document on the left and
return the new document. In all
cases, the variables on either side
remain unchanged.
subtracts the number on the right
from the number on the left and
return the new value. The variables
on either side remain unchanged. It
is not valid for any other object
types.
multiplies the numbers on both
sides of the " * " and return the new
value. The variables on either side
remain unchanged. It is not valid for
any other object types.
divides the number on the left by
the number on the right and return
the new value. The variables on
either side remain unchanged. It is
not valid for any other object types.
Modulo%For integer objects, this divides the
number on the left by the number
on the right and return the
remainder. The variables on either
side remain unchanged. It is not
valid for any other object types. For
example, 5/2 returns 1 since 5 / 2 is
2 with remainder 1.
9
Comparison
These operators are used to compare the values of variables or properties of the same type. The result
of the comparison is a boolean value (TRUE or FALSE). Any of the symbols listed for an operator can
be used.
OperatorSymbolsDescription
Less Than<, LTFor integers and reals, returns TRUE if the value
Greater Than>, GTFor integers and reals, returns TRUE if the value
Less Than or Equal To<=, LEFor integers and reals, returns TRUE if the value
Greater Than or Equal To>=, GEFor integers and reals, returns TRUE if the value
Equal To== , EQ
(double equal sign)
Not Equal To!=, <>, NEFor integers and reals, returns TRUE if the value
on the left is less than the value on the right. For
strings, returns TRUE if the value on the left
comes alphabetically before the value on the right
(including case). Returns FALSE otherwise.
on the left is greater than the value on the right.
For strings, returns TRUE if the value on the left
comes alphabetically after the value on the right
(including case). Returns FALSE otherwise.
on the left is less than or equal to the value on the
right. For strings, returns TRUE if the value on the
left comes alphabetically before or is the same as
the value on the right (including case). Returns
FALSE otherwise.
on the left is greater than or equal to the value on
the right. For strings, returns TRUE if the value on
the left comes alphabetically after or is the same
as the value on the right (including case). Returns
FALSE otherwise.
For integers and reals, returns TRUE if the value
on the left is equal to the on the right. For strings,
returns TRUE if the value on the left is exactly the
same (including case) as the value on the right.
Returns FALSE otherwise.
on the left is not equal to the on the right. For
strings, returns TRUE if the value on the left is not
exactly the same (including case) as the value on
the right. Returns FALSE otherwise.
10
Boolean
These operators are used to build complex boolean expressions. Each value on either side of the
operator must be a boolean value. The result of the boolean operator is a boolean value (TRUE or
FALSE). Any of the symbols listed for an operator can be used.
OperatorSymbolsDescription
And&, &&, ANDANDs two boolean values to get the final boolean
Or|, ||, ORORs two boolean values to get the final boolean
Not!, NOTNOTs a boolean value to get the final boolean
result.
result.
result.
The following table shows the results of the AND and OR methods using:
bool1 AND bool2
bool1 OR bool2
bool 1bool2ANDOR
FALSEFALSEFALSEFALSE
FALSETRUEFALSETRUE
TRUEFALSEFALSETRUE
TRUETRUETRUETRUE
11
Other Features
Object shorthand using "with"
If you have a section code that is working with the same object, it can be cumbersome to continually
type the object name. To avoid this, you can use the with statement. The general format is:
with objectname
.property = value
.property = value
.method()
endwith
You state the object name being used in the with statement and then you can refer to any property or
method of the object by simply using the "dot" followed by the property or method name. This is most
commonly used with the action objects.
Debugging a script
When a script executes, the action objects can write error and warning messages to the log. You can
also write your own messages to the log to help debug your script.
For example, you may want to know the value of a variable or the return value of a method. To write
your message to the log use the "debug" statement.
debug msg
msg can be a string variable, a string in quotes, or a numeric expression. Below are some examples:
int index= 3
string ErrorMsg = "Failed to print"
debug index
debug ErrorMsg
debug "Job received from " + original.username
Each of these writes a message to the server log.
Prompting for values during compilation
There may be circumstances when you do not want the sensitive data (such as userids or passwords)
to appear in the script for everyone to see. In that case, you can prompt for the data during script
compilation. This data is not visible in the script itself and it does not exist in an uncompiled form. To
use this feature, you use the preprocessor prompt directive:
#prompt{prompt msg}
The prompt message you want displayed is placed between the braces ( {} ). You cannot use a string
variable here and the text should not be in quotes. This is because the prompt is processed before the
compiler is in use and thus you cannot use other objects. The value returned by the prompt is a string
and contains whatever text was entered by the user.
The prompt can be placed anywhere a string is expected, such as:
FTPget.username = #prompt{Enter your FTP username}
12
If the prompt is used where a number is expected, assign a string to the value returned by the prompt
and then use the AsInt method. For example:
string copies = #prompt{Enter number of copies}
PrintIP.copies = copies.AsInt()
Aborting a script during runtime
If you detect an error condition during script execution, it is useful to have a means of halting the script
processing. To accomplish this, you use the exit function:
void exit(string msg)
The exit function halts processing of the script. It lets you pass a string which appears in the server’s
log as well as on the confirmation page/dialog.
Reserved words
A variable may not be any reserved word that already has a special meaning in the script language.
The following is the list of reserved words:
•If
•Then
•Else
•Endif
•Switch
•Case
•Default
•Endswitch
•Loop
•Exit
•From
•To
•Endloop
•Repeat
•Until
•Endrepeat
•String
•Textfile
•Int
•Confirm
•Doc
•Bool
•Binary
•BinaryFile
•Original
•Real
•Endwith
•Userdata
•Log
•Prompt
13
2
Data Type Objects
All data used by the Document Distributor can be grouped into five distinct data types:
•Boolean
•Document
•Integer
•Real
•String
Every object property is one of the Data Type Objects. In addition, most variables are one of these
types. Following is a discussion of each of these objects.
14
Boolean
The Boolean object is used for values that are logically true or false. The only valid values for this
variable are the reserved words: TRUE and FALSE.
The object has no properties. The following operators are supported:
Operators
SymbolDescription
==, EQEquals
<>Not Equal
&, ANDAnd
|, OROr
!, NOTNot
=Assignment
15
Document
The document object is used to hold a collection of image, text, and other formatted files. All files in a
document object do not have to be of the same type; it can be used to hold different files of different
types.
A property or variable is of this type when declared as doc. The document object has no properties.
Methods
SyntaxDescription
bool AddDocument(doc doc1)Adds an existing document to the end of this document.
Parameters:
doc1 – document to be added
Returns:
A bool indicating success or failure.
bool AddFile(string path [, string type])Adds an existing file to the end of this document. This method
will fail if the file does not exist or could not be read.
Parameters:
path – fully qualified path of the file on the server to be
added
type – if not supplied, the file type will be set to the
extension of the file being added; otherwise, the value
supplied will be used.
Returns:
A bool indicating success or failure.
void Clear()Removes all files from the document.
Parameters:
None
Returns:
None
doc CopyRange(int start, int end)Copies the specified files in this document to a new document;
this actually makes a copy of the files so two copies of the files
now exist. Doing this allows changes to be made to one set of
the files without affecting the other set.
Parameters:
start – index of the first file in document to copy; file
indexes start at 1
end – index of the last file in document to copy
Returns:
A doc that contains a copy of the files in the specified
range.
16
SyntaxDescription
doc Copy()Copies all the files in this document to a new document; this
int GetDocumentSize()Returns the total size in bytes of all the files in this document.
string GetDocumentType()Returns the type (file format or extension) of the document. If
doc GetFile(int filenum)Returns a reference to the specified file; the returned
string GetFileLabel(int filenum)Returns the label for the specified file. The label is used as the
int GetFileSize(int filenum)Returns the size in bytes of the specified file. A value of zero
actually makes a copy of the files so two copies of the files
now exist. Doing this allows changes to be made to one set of
the files without affecting the other set.
Parameters:
None
Returns:
A doc that contains of the copy all the files.
A size of zero (0) is returned if no files are in the document.
Parameters:
None
Returns:
An int with the total number of bytes in this document.
all the files in the document are the same type, the value is the
document type; otherwise, the value is an empty string.
Parameters:
None
Returns:
A string containing the document type (file format or
extension) of the document.
document is not a copy, so any change made to this file affects
the original. An empty document is returned if filenum is
invalid.
Parameters:
filenum – index of file to get; file indexes start at 1
Returns:
A doc containing a reference to the specified file.
filename (minus the extension) for attachments in e-mails or
databases. An empty string is returned if filenum is invalid.
Parameters:
filenum – index of file label to get; file indexes start at 1
Returns:
A string containing the label of the specified file.
(0) is returned if filenum is invalid.
Parameters:
filenum – index of file size to get; file indexes start at 1
Returns:
An int containing the size in bytes of the specified file.
17
SyntaxDescription
string GetFileType(int filenum)Returns the type (file format or extension) of the specified file.
doc GetFileRange(int start, int end)Returns a reference to the specified files; the returned
int GetNumberFiles()Returns the number of separate files in this document. This
bool SetFileLabel(int filenum, string label)Sets the label for the specified file; this label is used as the
An empty string is returned if filenum is invalid.
Parameters:
filenum – index of file type to get; file indexes start at 1
Returns:
A string containing the value of file type of the specified
file.
document is not a copy, so any change made to these files
affects the original.
Parameters:
start – index of first file to get; file indexes start at 1
end – index of last file to get
Returns:
A doc containing a reference to the specified files.
does not return the number of pages.
Parameters:
None
Returns:
An int with the number of files in this document.
filename (minus the extension) for naming attachments in
e-mail or databases. This method fails if filenum is invalid.
Parameters:
filenum – index of file; file indexes start at 1
label – label to give specified file; since it is used as a
filename, the label must follow the rules of file naming.
Returns:
A bool indicating success or failure.
void SetFileLabelAll(string label)Sets the labels of all the files in this document; this label is
used as the filename (minus the extension) for naming
attachments in e-mail or databases.
Parameters:
label – label to give all the files; since it is used as a
filename, the label must follow the rules of file naming.
Returns:
None
Note:For variables of type doc, assigning the variable is simply a reference. In other words, both
variables point to the same physical set of files that make up the document. So when you
make a change to one of the files, that file is changed in both documents. To make different
working copies of the files, use the Copy or CopyRange methods of the doc object.
18
Operators
SymbolDescription
+Add (same as calling AddDocument)
[]Index (same as calling GetFile using that one file)
=Assignment (same as calling GetFileRange using all files)
19
Integer
The integer object is used for values that are numbers without decimal points.
A property or variable is of this type when declared as int. The object has no properties.
Methods
SyntaxDescription
void Add(int num)Adds num to the current value. The value of this object
real AsReal()Converts and returns the current value of this object as
string AsString()Returns the current value of this object as a string.
void Divide(int num)Divides the current value by num. The value of this
is changed.
Parameters:
num – integer to be added to current value
Returns:
None
a real object. The value of this object is not changed.
Parameters:
None
Returns:
A real with the value of this object.
This is typically used so that the value of the integer
can be used as part of a string.
Parameters:
None
Returns:
A string with the value of this object.
object is changed.
Parameters:
num – integer to divide by
Returns:
None
void Mod(int num)Divides the current value by num and sets the value of
void Multiply(int num)Multiplies the current value by num. The value of this
this object to the remainder.
Parameters:
num – integer to divide by
Returns:
None
object is changed.
Parameters:
num – integer to multiply by
Returns:
None
20
Operators
SymbolDescription
<, LTLess Than
>, GTGreater Than
<=, LELess Than or Equal To
>=, GEGreater Than or Equal To
==, EQEquals
<>, NE, !=Not Equal
+Add
-Subtract
*Multiply
/Divide
%Modulo (Remainder)
=Assignment
Examples
StatementValue of XComment
int x0Declares variable
x = 55Assigns value of 5 to x
x.Mod(2)15/2 is 2 with remainder