Forcing Reference to Fields and Share Names

In order for BarTender to determine the best time to run your scripts during a print job and which database fields it will need to access, it examines the structure of your template and does a test run of your scripts. Among other factors, BarTender considers when and how any database fields and data source names are used.

The Problem with Conditional Execution

Conditional statements execute different "branches" of code, depending on how a conditional expression is evaluated. Accordingly, some code may not get executed, depending on the conditions at the time of the evaluation. This can cause a problem if a reference to a field or share name happens to be in code that gets skipped during BarTender's test run of its scripts. If the associated conditional statement evaluates differently at print-time and causes the field or share name to be referenced, and it didn’t get referenced during the previous test run, the script may not run at the most efficient time and may even fail.

Two Different Forcing Functions

The Script Assistant includes two functions that force a script to reference a database field or data source name. These functions don't change or assign any values, they simply force BarTender to notice the presence of an item that could be missed during the test run of a script. This ensures that BarTender will establish links to all of the necessary data fields and that your scripts will be executed in response to the appropriate events at print time.

To find the following two functions in the Script Assistant, double-click on Functions and then Declarations in the Category option. Then double-click on the desired reference function and field or share name in the Names option. The reference functions are best inserted into the beginning of your script before any conditional statements.

To Force Reference to a Data File Field

ReferenceField("field_name_or_field_number")

If the document is set up to read data from a regular text file, you will specify a field number. When reading from a database, you will specify a field name. Unless the field name itself is contained in a variable, be sure to put the name in quotes, such as ReferenceField("price"). 

To Force Reference to a Shared Data Source

ReferenceSharedSubString("share_name")

If you have given any data sources in the template a share name, you can force reference to them as shown above. (Unless the share name is stored in a variable, be sure to put quotes around it.)