Template Language Reference
AdvantageBuilder’s Template Language is designed to work with metadata‑driven builders such as GenericBuilder and SQL Server Builder. It allows you to generate code, scripts, and other text based on selected database objects and their properties, using a combination of Template Language directives, script blocks, and plain text.
Basic Concepts
A template is a text file that may contain Template Language directives. When executed, these directives are replaced with values derived from the selected objects and the current context.
Templates can contain:
- Template Language directives
- JScript blocks
- JavaScriptV8 blocks
- PowerShellScript blocks
- Plain text
Common uses include:
- Generating stored procedures
- Generating table scripts
- Generating data access classes
- Generating configuration files
- Generating documentation
Template Inputs
When a template is executed against selected objects, the Template Language exposes metadata through
the input object.
Typical properties include:
input.DatabaseNameinput.ObjectNameinput.ProcedureNameinput.Columnsinput.Parameters
Column/parameter metadata includes:
- Name
- IsSelected
- DbDataType / NativeDBDataType
- DotNetDataType
- Length
- Scale
- Precision
- DefaultValue
Core Directives
Core directives map directly to metadata fields:
[!DATABASE_NAME][!OBJECT_NAME][!PROCEDURE_NAME][!COLUMN_NAME][!PARAMETER_NAME][!DB_DATA_TYPE][!DOT_NET_DATA_TYPE][!DEFAULT_VALUE][!LENGTH][!SCALE][!PRECISION]
Example:
[!FOR_EACH_COLUMN]
Column Name: [!COLUMN_NAME]
Selected: [!IF_SELECTED]Yes[!ELSE]No[!/IF_SELECTED]
[!/FOR_EACH_COLUMN]
Loop Directives
Loop directives iterate over metadata collections.
[!FOR_EACH_COLUMN]
[!/FOR_EACH_COLUMN]
[!FOR_EACH_PARAMETER]
[!/FOR_EACH_PARAMETER]
Example:
[!FOR_EACH_COLUMN]
[!COLUMN_NAME] [!DB_DATA_TYPE],
[!/FOR_EACH_COLUMN]
Conditional Directives & Inline Functions
Conditional directives include:
[!IF_SELECTED]
[!IF_SELECTED_ELSE]
[!/IF_SELECTED]
Inline functions:
[!IIF]Condition[!T]TrueExp[!F]FalseExp[!/IIF][!REPLACE]Expr[!O]Old[!N]New[!/REPLACE]
Examples:
[!FOR_EACH_COLUMN]
[!COLUMN_NAME] [!IIF][!DB_DATA_TYPE] = "varchar"[!T]string[!F]other[!/IIF]
[!/FOR_EACH_COLUMN]
[!REPLACE]dbo.[!O]app.[!N][!DB_NAME].[!TABLE_NAME][!/REPLACE]
JScript Integration
JScript blocks allow complex logic, metadata processing, SQL execution, and text generation.
[!JSCRIPT]
writeln("Database: " + input.DatabaseName);
for (var i = 0; i < input.Columns.length; i++)
{
var col = input.Columns[i];
if (col.IsSelected)
{
writeln("Selected Column: " + col.Name + " (" + col.DbDataType + ")");
}
}
[!/JSCRIPT]
SQL Execution from JScript
[!JSCRIPT]
var sql = "SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" +
input.TableName + "'";
var ds = ExecuteDataset(sql, 2, connectionString);
if (ds != null && ds.Tables.Count() > 0)
{
var table = ds.Tables[0];
for (var row in table.Rows)
{
var name = table.Rows[row]["COLUMN_NAME"];
var type = table.Rows[row]["DATA_TYPE"];
writeln(name + " " + type);
}
}
ds = null;
[!/JSCRIPT]
JavaScriptV8 Integration
JavaScriptV8 blocks run under ClearScript V8 and can access metadata, .NET objects, and the ObjectStore.
[!JAVASCRIPTV8]
writeln("Table: " + input.ObjectName);
for (var i = 0; i < input.Columns.length; i++)
{
var col = input.Columns[i];
if (col.IsSelected)
{
writeln("Selected Column: " + col.Name + " (" + col.NativeDBDataType + ")");
}
}
addToObjectStore("SelectedCount", input.Columns.filter(c => c.IsSelected).length);
[!/JAVASCRIPTV8]
PowerShellScript Integration
PowerShellScript blocks run under the PowerShell engine and can access metadata, ObjectStore, and .NET APIs.
[!POWERSHELLSCRIPT]
"Database: " + $_input.DatabaseName
$_input.Columns.ForEach({
if ($_.IsSelected)
{
"Selected Column: " + $_.Name + " (" + $_.NativeDBDataType + ")"
}
})
$selectedCount = getFromObjectStore "SelectedCount"
"Selected Count from ObjectStore: " + $selectedCount
[!/POWERSHELLSCRIPT]
ObjectStore Integration
ObjectStore allows templates and macros to share values across engines.
[!SET]hello[!TO]123[!/SET]
Template Language: [!VAR]hello[!/VAR]
[!POWERSHELLSCRIPT]
$someVar = getFromObjectStore "hello"
"PowerShellScript: " + $someVar
[!/POWERSHELLSCRIPT]
[!JAVASCRIPTV8]
var jsTest = getFromObjectStore("hello");
writeln("JSV8: " + jsTest);
[!/JAVASCRIPTV8]
[!JSCRIPT]
var jsTest = getFromObjectStore("hello");
writeln("JScript: " + jsTest);
[!/JSCRIPT]
Macro Parameters and Arguments
Macros can receive parameters via args (JScript/V8) or $_args (PowerShellScript).
Called macros can modify these values, and the calling macro will see the updated values.
[!JSCRIPT]
if (args != null)
{
args.sum = eval(args.x) + eval(args.y);
}
[!/JSCRIPT]
The text produced by the called macro is always returned by callMacro.
var result = callMacro(false, "Get a shopping list", "Hello World\\Helper Macros");
writeln(result);
Summary:
- Pass values into macros
- Modify values inside macros
- Return modified values to the caller
- Always return generated text
- Share data across engines
- Use strongly typed .NET objects
AdvantageBuilder API Integration
Templates and script blocks can call .NET API functions exposed by AdvantageBuilder, including:
- callMacro
- callMacroAsync
- showHTMLForm
- launchHTMLForm
- getGUIFilePath
- write / writeln
- updateProgress
- setStatusText
Example (JavaScriptV8):
[!JAVASCRIPTV8]
var doc = showHTMLForm(getGUIFilePath("SampleScreen.htm"));
if (doc != null)
{
let value = doc.forms[0]["txtInput"].value;
writeln("User entered: " + value);
}
[!/JAVASCRIPTV8]
Example (JScript):
[!JSCRIPT]
updateProgress(10);
setStatusText("Running macro...");
var result = callMacro(true, 'Insert Macro Name', 'Insert Macro Path', params);
[!/JSCRIPT]
Using Templates Against Selected Objects
Templates can be executed directly against selected GenericBuilder or SQL Server Builder objects.
The input object is populated based on the current selection.
Typical workflow:
- Select tables, views, or procedures
- Choose a template
- Execute the template
- Review generated output
[!FOR_EACH_COLUMN]
[!COLUMN_NAME] [!DB_DATA_TYPE],
[!/FOR_EACH_COLUMN]
Summary
The Template Language, together with JScript, JavaScriptV8, and PowerShellScript blocks, provides a powerful and flexible way to generate code and text based on metadata and runtime context. It supports SQL execution, ObjectStore integration, .NET API calls, macro parameters, nested macro calls, and direct execution against selected GenericBuilder and SQL Server Builder objects.
By combining Template Language directives with script blocks, you can build sophisticated generators for stored procedures, table scripts, data access layers, configuration files, documentation, and any other text‑based automation required in your workflow.