Open topic with navigation
Advanced users who have knowledge of the JavaScript language can use expressions to perform string, mathematical, or other advanced operations on variables.
Syntax
The valid syntax to use is as follows:
<%Expression%>
The expression that is enclosed by <% and %> is evaluated by the JavaScript engine. There must be no space characters just after the starting <% or just before the ending %>.
Examples of valid syntax are as follows:
Examples
You can use expressions in instances where a variable reference is used to read a variable's value. The following procedures give examples of where you can implement them in BarTender.
To define the value of a custom global variable
-
Click the Administration tab.
-
Click Options.
-
Under Custom Global Variables, click Add Variable.
-
In the Name field, enter a name for the custom variable.
-
In the Value field, enter the JavaScript expression that you want. For example, enter the following expression:
<%UserName.substr(0, UserName.lastIndexOf('\\'))%>
To specify the path of a document to print in a Print Document action
-
Click the Create tab.
-
In the Events pane of the Create view, click to expand the event that contains the Print Document action that you want.
-
Click the Print Document action.
-
On the Document tab, click in the Document field.
-
Enter the JavaScript expression that you want. For example, enter the following expression:
<%DetectedFilePath.substr(0, DetectedFilePath.lastIndexOf('.')) + ".btw"%>
To set a variable's value in a Set Variable action
-
Click the Create tab.
-
In the Events pane of the Create view, click the event that you want, and then add a Set Variable action to it.
-
On the Set One Variable tab, under Variable, click in the Value field.
-
Enter the JavaScript expression that you want. For example, enter the following expression:
<%DetectedFilePath.substr(0, DetectedFilePath.lastIndexOf('.')) + ".btw"%>
To write a message that contains a variable expression in a Write Message to Log action
-
Click the Create tab.
-
In the Events pane of the Create view, click the event that you want, and then add a Write Message to Log action to it.
-
On the Write Message tab, under Message, click in the Variable field.
-
Enter the JavaScript expression that you want. For example, enter the following text and expression:
File '<%DetectedFilePath.substr(0, DetectedFilePath.lastIndexOf('.')) + ".btw"%>' in %DetectedFileFolder% is being printed.
To set an action's Action property to run the action conditionally
-
Click the Create tab.
-
In the Events pane of the Create view, click the event that you want.
-
Add the action that you want.
-
On the Action tab, click Conditionally, based on variable or Conditionally, based on expression.
-
Click in the variable field that you want to add the JavaScript expression to.
-
Enter the JavaScript expression that you want. For example, enter the following expression:
<%new Date().getMonth() + 1)%>
To specify which case action to run based on an expression evaluation result in a Select Case action
-
Click the Create tab.
-
In the Events pane of the Create view, click the event that you want, and then add a Select Case action to it.
-
On the Select Case tab, under Cases, click in the Select case using variable field.
-
Enter the JavaScript expression that you want. For example, enter the following expression:
<%Number(Variable1) + 0.1 + 0.2 + 55%>
To iterate over start, end, or increment values that are specified by expressions in a For Loop action
-
Click the Create tab.
-
In the Events pane of the Create view, click the event that you want, and then add a For Loop action to it.
-
On the For Loop tab, under Options, click in the Name of iteration variable field.
-
Enter the JavaScript expression that you want. For example, enter the following expression:
<%RD_Documents.length - 1%>
Objects that can be used in expressions
-
All defined variables can be used, whether they are defined as built-in or custom or they received their values in run time by the trigger event data. Do not use undefined variables.
-
Reserved names must not be used for variables. Because expressions are evaluated as JavaScript expressions, some names conflict with JavaScript language and must be avoided. These names include JavaScript reserved words, such as for and var, and the names of built-in JavaScript objects, such as Math and JSON.
-
All the built-in JavaScript objects can be used, such as Math, RegExp and JSON. However, not all objects are valid expression evaluation results.
Valid evaluation result types
All built-in JavaScript objects can be used in the expression, but not all of them are valid expression evaluation results. The following JavaScript types are accepted as valid: