Placeholders

From Dafne documentation
Jump to navigation Jump to search

Placeholders are markers substituted with their current values before a statement is executed. They are available in task commands, in scenario planning queries and in operator notification commands.

Syntax

A placeholder is written as the name enclosed in percent signs:

%taskid%

All occurrences are replaced, so a placeholder may be used more than once in the same statement.

User-defined parameters use the u: prefix to distinguish them from system placeholders:

%u:parameter_name%

The named parameter must exist in the parameter list. See Parameter.

Placeholders in task commands

Available in the task Query field
Placeholder Value
%scenarioid% Scenario ID
%scenarioname% Scenario name
%groupid% Group ID
%groupname% Group name
%taskid% Task ID
%taskname% Task name
%period% Task period type (D=Daily, W=Weekly, M=Monthly)
%processingid% Processing ID
%processingname% Processing name
%iteration% Processing iteration code
%date% Processing date, format YYYY-MM-DD
%date_n% Processing date, numeric format YYYYMMDD
%date_dt% Processing date, timestamp format YYYY-MM-DD 00:00:00.000
%processingstart_n% Processing start time, format yyyyMMddHHmmss
%execid% Scheduled task ID. Keeps its value across attempts within one processing.
%runid% Run ID. Unique for every attempt.
%trynumber% Attempt number of the scheduled task within the processing.
%env% Environment code (P=Prod, T=Test, D=Dev, U=UAT, S=SIT, O=Other1, Q=Other2)

Three date forms are provided because target systems differ in what they accept. Use %date_n% where a numeric partition key is expected and %date_dt% where a timestamp is required, rather than converting %date% in the statement.

Note the difference between %execid% and %runid%: the first identifies the scheduled task and is stable across retries, the second identifies the individual attempt. Use %runid% when logging so that each attempt can be distinguished.

Example

insert into my_table (taskid, date, scenarioid) values (%taskid%, '%date%', %scenarioid%);

With a user-defined parameter:

call proc1(%u:usrpar1%)

Placeholders in scenario planning queries

A different set is available in the planning query of a Scenario, describing the state of previous processings:

Placeholder Value
%scenarioid% Scenario ID
%scenarioname% Scenario name
%maxdate% Latest finished processing date. Defaults to 1970-01-01 on the first run.
%maxprocessingID% ID of the last finished processing. Defaults to 0 on the first run.
%maxIteration% Iteration code of the last finished processing.
%maxIterationAll% Iteration code of the last started processing.
%maxProcessingName% Name of the last finished processing.
%maxProcessingStatus% Status of the last started processing. Defaults to F on the first run.

Example

select %maxdate% + 1 as date, 'iter1' as iteration

Placeholders in notification commands

The notification command of an Operator may use placeholders identifying the failed task and its processing — the task and group, the processing and its date and iteration, and the scenario. See Operator.

Quoting

Substitution is textual. A placeholder is replaced by its value exactly, without quoting or escaping, so string values must be quoted in the statement itself:

where business_date = '%date%'

For the same reason, treat a user-defined parameter whose value comes from a query as untrusted input when building SQL, and prefer passing it as an argument to a procedure over concatenating it into a statement.

Checking the result

The Query tab of the scheduled task detail in the Monitor console shows the executed query — the statement after substitution. This is the reliable way to confirm what a placeholder resolved to, and the first place to look when a task fails with an unexpected value.

See also