Using the template editor in ApexSQL Trigger

Applies to:
ApexSQL Trigger

This article describes the ApexSQL Trigger trigger template editor and its use


An important feature of ApexSQL Trigger, for advanced users, is its ability to customize trigger code patterns. ApexSQL Trigger provides a professional editor/IDE with syntax highlighting, auto-complete, line numbering, parsing and debugging features for this purpose

Trigger templates employ the exact same paradigm as Active Server Pages, the dynamic web authoring technology from Microsoft, as well as the same scripting languages – Microsoft VBScript and JScript. The script parser and debugger are the same for both ApexSQL Trigger templates and ASP

The template editor

The template editor is accessed by clicking on the Edit template button, in the Home tab:

The template from the current auditing architecture profile will be loaded upon accessing the template editor

The template editor has three script panes:

  • Template – the core of the template editor. All adjustments to the trigger templates are achieved through it
  • Script source – the actual code executed against the Microsoft Script Parser. This pane is primarily used for debugging purposes.  If there is a run time error in the template, the editor will display an error dialog box
  • Results – assuming the Trigger template processed without error, the resulting Trigger Script will be output to the Results pane.

The Template pane

This is the main working area of the editor. Through it new trigger templates can be created and existing templates can be edited

The template editor supports bookmarks

Quick tip icon

Quick tip:

A bookmark is a way to easily navigate between points of interest in triggers template

This pane also holds the template property page which is used to assign template attributes. It has five fields, and notable is the Includes which allows to select the include files

Managing include files

Support for Include files is a feature of ApexSQL Trigger templates. Include files, just like in HTML and ASP allow you to link a file to one or more libraries of code, usually functions, constants, and other. This way libraries can easily be re-used for multiple templates.

In the case of ApexSQL2053.audx – the default architecture included with ApexSQL Trigger installation – one include file is used the This file contains several VBScript functions used for code formatting

To implement additional includes the following procedure is used:

  1. Select the Includes row in the template property page, and click on the button in the right corner.

  2. In the form that appears, you can add or remove include files. If the include files are not stored in the same directory as the template that calls it, check the Use a full file path option – this will hard code the full path to this file. Otherwise select Use a template path option:

Template parsing

A feature of the template editor is template parsing.  It will look for mismatched script tags and help avoid potentially hard to debug errors. Currently, template parsing exists for missing script tags {% and %}.

There are three ways the parser can be run:

  • Click on the checked button in the toolbox

  • Go to the Run menu and click on the Parse option

  • Use the Ctrl+F5 shortcut

If there is a missing script tag, the template parser will detect it and raise a warning to the user

In this example the closing tag is missing:

After parsing this message will be shown: