Enhancement Engine APIs
Use this guide to write JavaScript functions that edit a label request and combine these functions into programs in Enhancement Engine.
About Enhancement Engine APIs
To use Enhancement Engine, you write JavaScript functions that edit a label request, and combine these functions into programs. In addition to regular JavaScript functions, a number of objects and methods are provided by Enhancement Engine.
[Body Empty]
About labels
Labels are the primary objects operated on by scripts. Label objects contain all of the information from incoming label requests. The label objects represent the outgoing label request that is sent to the printer. Label objects make the following attributes available for the user to read, change, or both.
-
Format
-
Quantity
-
Printer name
-
Job name
-
Variables
A request can contain multiple labels. You can set the first four attributes for all the labels as a whole or individually for each label.
The ‘labels' object is present by default in all scripts. For example, setting the job name on a label object could be completed with:
labels.jobName = “NewJobName”To get the first label in a label request:
var firstLabel = labels.getlabel(0);Many label requests contain only one label, therefore the first label is also available by default as ‘label'. For example, setting the job name of the first label:
label.jobName = “NewJobName”Attribute values are accessed through the = operator, as above, or use traditional programming get and set commands:
var newVar = label.getJobName();This is equivalent to:
var newVar = label.jobName; label.setJobName(“NewJobName”);which is then equivalent to:
label.jobName = “NewJobName”;Either method can be used. These are documented more fully in the API section.
Again, ‘labels' and ‘label' are special objects that are always available. As a user you do not need to define them. A typical label transformation involves changing the value of one or more variables. This can be completed by:
label.setVariable(“VariableName”, “New Variable”);The setVariable method updates a variable if it already exists or adds a new variable if it does not.
A copy of the labels as they existed before the script started is preserved in the ‘originalLabels' array variable. This is provided mostly for debugging and this variable is not used when printing to EPP.
About database access
Data sources are defined in the Administration section of EPP. Once data sources are defined they can be accessed in scripts directly by name. To retrieve information from a database, the ‘query' method can be used, for example:
var results= TestDatabase.query(“select * from wid- get”);Another example:
var results = TestDatabase.query(“select * from wid- get”);' TestDatabase' is the name of a data source already defined. Parameters can be used in the query:
var args = []; args [0] = 2; args [1] =”BestWidget”; var results = TestDatabase.query ( “SELECT * FROM WIDGET WHERE WIDGET_ID = ? and WIDGET_NAME = ?”, args);First, an array named ‘args' is created. Arguments for the query are then loaded into it. This example has two arguments. The first argument is substituted for the first question mark and the second is substituted for the second question mark.
Note: It is recommended that you create dates using the custom date method, newDate().
Normally, users do not have to worry about variable types, but variable types do need to be considered when creating arguments to pass in to sql commands.
var aDate = newDate(“2009-12-31”)To use a different date format, you can use a second argument:
var aDate = newDate(“12-31-2009”, MM-DD-YYYY”);For Boolean variables, use the newBoolean function:
var aBoolean = newBoolean(“true”)The results variable stores the results of the query. A number of methods are available for the query results:
-
hasResults() - Returns true if results were retrieved; false if not.
-
numRows() - Returns the number of rows returned by the query.
-
row() - Returns a row of results.
-
rows() - Return all rows.
-
column() - Returns a column from a row of results
results.row(0).column(“NAME”)This script would return the name from the first row. Because many queries are intended to return only one row of results, a shortcut is available:
results.column(“NAME”)This script is equivalent to the command above with the ‘NAME' value of the first row being the results returned.
To loop through all of the results:
var rows = results.rows(); for (i = 0; i , rows.length; i++){ println(rows[i].column(“NAME”) ) ]
About Emailing information
You can access e-mail functionality from within scripts by defining a SMTP mail server in Administration > Settings. For example, the following command can send an email.
sendMail(recipient,sender,subject,body);The mail server defined in Settings is available by default in the scripts as the variable ‘mailServer' and can be used for more complicated e-mails, as demonstrated in the following example.
var emailMessage = newEmailMessage(); emailMessage.body = “body”; emailMessage.subject = “subject”; emailMessage.sender = “sender email address”; var recipients = []; recipients[0] = “first email address”; recipients[1] = “second email address”; emailMessage.setToList(recipients); var ccRecipients = []; ccRecipients [0] = “first email address”; ccRecipients [1] = “second email address”; emailMessage.setCcRecipient(ccRecipients); var bccRecipients = []; bccRecipients [0] = “first email address”; bccRecipients [1] = “second email address”; emailMessage.setBccRecipient(bccRecipients); mailServer.send(emailMessage);
About printing with Enhancement Engine
A label request is passed on only if there is an explicit command to do so in the script:
printLabels(labels);
Special methods
Special methods are provided for convenience in Enhancement Engine scripts. Any method from standard Enhancement Engine classes can be used.
The following methods are available for use in all scripts. They are available globally in the scripts and do not need to be called on any objects.
newBoolean(booleanValue)
Returns a Boolean object.
newDate(dateValue)
Returns a date object for the given date. The date must be formatted as “YYYY-MM-DD”, eg. “2009-12-31”.
newDate(dateValue, dateFormat)
Returns a date object for the given date. The date should be in the format of the dateFormat given. For example, to pass in a date of “12-31-2009”, the format would need to be (“MM-DD- YYYY”).
newEmailMessage ()
Returns an E-mail Message that the mailServer object can send.
newSqlType(name)
Returns a Sql Type object. This is needed for certain stored procedure output parameters. The following are legal types along with the data types they create:
DATE | java.sql.Types.DATE |
BOOLEAN | java.sql.Types.BOOLEAN |
CHAR | java.sql.Types.CHAR |
DECIMAL | java.sql.Types.DECIMAL |
DOUBLE | java.sql.Types.DOUBLE |
FLOAT | java.sql.Types.FLOAT |
INTEGER | java.sql.Types.INTEGER |
NUMERIC | java.sql.Types.NUMERIC |
TIMESTAMP | java.sql.Types.TIMESTAMP |
TIME | java.sql.Types.TIME |
VARCHAR | java.sql.Types.VARCHAR |
VAR | java.sql.Types.VAR |
printLabels(labels)
Sends a Labels object for printing.
sendMail(recipient, sender, subject, body)
Uses the mail server configured in settings to send an e-mail to the recipient from the sender with the given subject and body.
Special objects
Special objects are provided for convenience in Enhancement Engine scripts.
These objects are available by default in all scripts.
label
The first label in the labels array from the XML label request.
labels
The labels array from the XML label request.
mailServer
A mail server configured from the SmtpMailServer setting that can send e-mails.
originalLabels
A copy of the labels. These should be used as a convenient reference for the original state of the labels before any transformations started and should not be changed.
QueryResultRow reference guide
Wrapper around a result row returned from a database.
Member functions
-
QueryResultRow (Map<String, Object>columns)
-
Object column (String columnName) Returns the object in the column.
-
Map<String, Object>columns() Returns a map of all columns where the key holds the column name and the value is the object in the column.
QueryResults reference guide
Wrapper around results from a database query.
Member functions
-
QueryResults (List<QueryResultRow>results, Integer numRows)
-
QueryResultRow row (int rowNumber) Returns a row as a QueryResultRow object.
-
Object column (String columnName) Returns an object for the column name given in the first row of results.
-
QueryResultRow [] rows () Returns all rows.
-
Integer numRows () Returns the number of rows in the results.
-
boolean hasResults () Returns true if the query had results—false if not.
StoredProcedure reference guide
Representation of a database stored procedure.
Member functions
-
StoredProcedure (String name, int noOfParms)
-
void addInParameter (Integer position, Object parameterValue)
-
void addOutParameter (Integer position, SqlType sqlType)
-
String getName ()
-
Integer getNoOfParms ()
-
Map<Integer, Object > getInParms ()
-
Map<Integer, SqlType > getOutParms ()
Static variables
-
static final int DATE = java.sql.Types.DATE
StoredProcedureResults reference guide
Representation of stored procedure results.
Member functions
-
StoredProcedureResults (QueryResults queryResults)
-
QueryResults getQueryResults ()
-
void addOutParameter (Integer parameterIndex, Object parameter)
-
Object getOutParameter (Integer parameterIndex)
DataSource reference guide
An Oracle or MS SQL Server database can be queried for information or updated from a script.
Member functions
-
int execute (String sql)
-
QueryResults query (String sql)
-
QueryResults query (String sql, Object[] parms)
-
StoredProcedureResults call (StoredProcedure storedProc)
-
StoredProcedureResults callWithResults (StoredProcedurestoredProc)
-
void serializeToXMLFile (String xmlFilePath)
-
void close ()
-
boolean testConnection ()
Package functions
int execute (String sql, Object [] parms)
Label reference guide
A label.
Member functions
-
Label copy () Returns a copy of the label.
-
String getVar (String name) Gets a variable.
-
String getVariable (String name) Gets a variable.
-
void setVar (String name, String value) Sets a variable.
-
void setVariable (String name, String value) Sets a variable.
-
String getFormat () Gets the label's ‘format' attribute.
-
void setFormat (String format) Sets the label's ‘format' attribute.
-
void setVariables (List<Variable>variables).
-
String getJobName () Gets the label's ‘job name' attribute.
-
void setJobName (String jobName) Sets the label's 'job name' attribute.
-
String getQuantity () Gets the label's ‘quantity' attribute.
-
void setQuantity (String quantity) Sets the label's ‘quantity' attribute.
-
String getDuplicates () Gets the label's ‘duplicates' attribute.
-
void setDuplicates (String duplicates) Sets the label's ‘duplicates' attribute.
-
String getPages () Gets the label's ‘pages' attribute.
-
void setPages (String pages) Sets the label's ‘pages' attribute.
-
String getPrinterNumber () Gets the label's ‘printer number' attribute.
-
void setPrinterNumber (String printerNumber) Sets the label's ‘printer number' attribute.
-
String getPrinterNumber () Gets the label's ‘printer name' attribute.
-
void setPrinterName (String printerName) Gets the label's ‘printer name' attribute.
-
List<Variable>getVariables () Gets a list of the label's variables.
Variables
-
List<Variable>variables = new VariablesArrayList<Variable>()
-
String format
-
String jobName
-
String quantity
-
String duplicates
-
String pages
-
String printerNumber
-
String printerName
Labels reference guide
The Labels class represents a set of Label objects.
Member functions
-
void addLabel (Label label)
-
Label getLabel (int index)
-
void setVar (String name, String value) Sets variable on every label.
-
void setVariable (String name, String value) Sets variable on every label.
-
String toString()
-
int size () Number of labels
-
void setLabelList (List<Label>labelList)
-
Labels copy () Copies the labels to a new Labels object.
-
void propagateDefaults () Sets all label element attributes, which are null to the parent labels corresponding attributes.
-
String getFormat () Gets the labels ‘format' attribute.
-
void setFormat (String format)Sets the labels ‘format' attribute.
-
String getJobName () Gets the label's ‘job name' attribute.
-
void setJobName (String jobName) Sets the label's ‘job name' attribute.
-
String getQuantity () Gets the label's ‘quantity' attribute.
-
void setQuantity (String quantity)Sets the label's ‘quantity' attribute.
-
String getDuplicates () Gets the label's ‘duplicates' attribute.
-
void setDuplicates (String duplicates) Sets the label's ‘duplicates' attribute.
-
String getPages () Gets the label's ‘pages' attribute.
-
void setPages (String Page)Sets the label's ‘pages' attribute.
-
String getPrinterNumber () Gets the label's ‘printer number' attribute.
-
void setPrinterNumber (String printerNumber) Sets the label's ‘printer number' attribute.
-
String getPrinterName () Gets the label's ‘printer name' attribute.
-
void setPrinterName (String printerName) Gets the label's ‘printer name' attribute.
-
List<Label>getLabelList ()
Variables
-
String format
-
String quantity
-
String jobName
-
String duplicates
-
String pages
-
String printerNumber
-
String printerName
-
List<Label>labelList
MailServer reference guide
An SMTP mail server configured from the application's settings.
Member functions
-
void send (EmailMessage message) Sends an e-mail message.
-
String getType () Returns the type of mail server.
-
String getMailhost ()
-
Integer getPort ()
Loading...
There was a problem loading this topic