Using Expressions with Variables

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.

ClosedTo define the value of a custom global variable

  1. Click the Administration tab.

  2. Click Options.

  3. Under Custom Global Variables, click Add Variable.

  4. In the Name field, enter a name for the custom variable.

  5. In the Value field, enter the JavaScript expression that you want. For example, enter the following expression:

    <%UserName.substr(0, UserName.lastIndexOf('\\'))%>

ClosedTo specify the path of a document to print in a Print Document action

  1. Click the Create tab.

  2. In the Events pane of the Create view, click to expand the event that contains the Print Document action that you want.

  3. Click the Print Document action.

  4. On the Document tab, click in the Document field.

  5. Enter the JavaScript expression that you want. For example, enter the following expression: 

    <%DetectedFilePath.substr(0, DetectedFilePath.lastIndexOf('.')) + ".btw"%>

ClosedTo set a variable's value in a Set Variable action

  1. Click the Create tab.

  2. In the Events pane of the Create view, click the event that you want, and then add a Set Variable action to it.

  3. On the Set One Variable tab, under Variable, click in the Value field.

  4. Enter the JavaScript expression that you want. For example, enter the following expression: 

    <%DetectedFilePath.substr(0, DetectedFilePath.lastIndexOf('.')) + ".btw"%>

ClosedTo write a message that contains a variable expression in a Write Message to Log action

  1. Click the Create tab.

  2. 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.

  3. On the Write Message tab, under Message, click in the Variable field.

  4. 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.

ClosedTo set an action's Action property to run the action conditionally

  1. Click the Create tab.

  2. In the Events pane of the Create view, click the event that you want.

  3. Add the action that you want.

  4. On the Action tab, click Conditionally, based on variable or Conditionally, based on expression.

  5. Click in the variable field that you want to add the JavaScript expression to.

  6. Enter the JavaScript expression that you want. For example, enter the following expression:

    <%new Date().getMonth() + 1)%>

ClosedTo specify which case action to run based on an expression evaluation result in a Select Case action

  1. Click the Create tab.

  2. In the Events pane of the Create view, click the event that you want, and then add a Select Case action to it.

  3. On the Select Case tab, under Cases, click in the Select case using variable field.

  4. Enter the JavaScript expression that you want. For example, enter the following expression:

    <%Number(Variable1) + 0.1 + 0.2 + 55%>

ClosedTo iterate over start, end, or increment values that are specified by expressions in a For Loop action

  1. Click the Create tab.

  2. In the Events pane of the Create view, click the event that you want, and then add a For Loop action to it.

  3. On the For Loop tab, under Options, click in the Name of iteration variable field.

  4. Enter the JavaScript expression that you want. For example, enter the following expression:

    <%RD_Documents.length - 1%>

Objects that can be used in expressions

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: