29 May 2026 02:27 PM
I am attempting to build my own custom SLO dashboard using the Grail SLOs we have defined in our environment. I am able to successfully query the SLO list using javascript and I can list out the metadata found on the SLOs. One piece of information is the DQL that is used to build the SLI data and generate the SLO. I want to capture that query, set it as a dashboard variable and then run that query on another panel. So far I have been unsuccessful on the last part, running the query on a separate panel.
29 May 2026 02:44 PM
Hello @gdalessandro ,
I think the limitation here is how dashboard variables work.
Variables can be used to pass values into a DQL query, for example an SLO name, ID, tag, or filter value. But they are not intended to replace or execute the full DQL query of another tile.
So something like this usually will not work:
$SloQuery
Even with options like :noquote, the variable is still value substitution, not dynamic DQL execution.
I would suggest using the variable only to select the SLO, for example by SLO ID or name, and then use fixed DQL queries in the dashboard panels that filter based on that selected value.
If you really need to read the SLO definition, extract its DQL, execute it, and render the result dynamically, that logic is better suited for a Code tile, Notebook, Workflow, or even a custom App.
29 May 2026 04:48 PM
I am doing this in a code tile and it is still failing for the same reasons you describe above.
async function runDqlQuery () {
const environment = "https://{environmentid}.apps.dynatrace.com"; // Replace with your Dynatrace environment URL
const token ="dt****************0"; // Replace with your API token
const params = '/platform/storage/query/v1/query:execute?enrich=metric-metadata';
const query = $sliQuery ;
const uri = environment + params;
try {
const body={
query: query
}
const response = await fetch(uri, {
method: "POST",
headers: {
Accept: "application/json",
'Content-type': "application/json",
Authorization: "Bearer " + token
},
body: JSON.stringify(body) // Convert JS object to JSON string
});
console.log(response)
// Handle HTTP errors
if (!response.ok) {
throw new Error(`HTTP ${response.status} - ${response.statusText}`);
}
// Parse JSON result
const data = await response.json();
// Log raw result
console.log("Raw DQL Response:", JSON.stringify(data, null, 2));
// Example: Extract and print table rows
if (data.result && data.result.records) {
console.log("Query Results:");
data.result.records.forEach((row, idx) => {
console.log(`${idx + 1}:`, row);
});
} else {
console.log("No records found.");
}
} catch (err) {
console.error("Error executing DQL query:", err);
}
//return query
}
// Run the query
runDqlQuery();{
"error": {
"code": 540,
"message": "Execution crashed.",
"details": {
"logs": "ReferenceError: $sliQuery is not defined\n at runDqlQuery (file:///script.ts:9:17)\n at file:///script.ts:57:1\n",
"type": "UNCAUGHT_EXCEPTION",
"message": "Uncaught (in promise) ReferenceError: $sliQuery is not defined",
"details": {
"sourceLine": " const query = $sliQuery ;",
"lineNumber": 9,
"startColumn": 17,
"stack": "ReferenceError: $sliQuery is not defined\n at runDqlQuery (file:///script.ts:9:17)\n at file:///script.ts:57:1"
}
}
}
}
29 May 2026 04:57 PM - edited 29 May 2026 04:58 PM
Thanks, since this is running in a Dashboard Code tile, I would first check how $sliQuery is defined at the dashboard level.
Could you share the configuration of the sliQuery dashboard variable?
Mainly:
Returned value:
So the next thing to confirm is whether sliQuery is really configured as a dashboard variable and whether the variable name matches exactly. For example, if the variable is named SliQuery, sli_query, or sliQuery, the reference needs to match the supported dashboard variable syntax exactly.
Also, since the value appears to be a full DQL query, it would be useful to confirm whether the variable is being injected as plain text/string or whether the Code tile is trying to interpret it as JavaScript code.
29 May 2026 06:01 PM - edited 29 May 2026 06:03 PM
variable name: sliQuery
Multiselect (default value is *)
value returned when using console.log in the javascript for the variable:
/*
* This function will run in the Dynatrace JavaScript runtime.
* For information visit https://{environmentid}.apps.dynatrace.com"
const token ="dt****************";
const params = '/platform/slo/v1/slos/evaluation:start';
const uri = environment + params;
const body={id: String($ID),
filterSegments: [
{
id: "string",
variables: [
{
name: "string",
values: [
"string"
]
}
]
}
],
customTimeframe: {
timeframeFrom: "now-7d",
timeframeTo: "now"
},
requestTimeoutMilliseconds: 1000};
const response = await fetch(uri, {
method: "POST",
headers: {
Accept: "application/json",
'Content-type': "application/json",
Authorization: "Bearer " + token
},
body: JSON.stringify(body) // Convert JS object to JSON string
});
const result = await response.json();
console.log(result.metadata.evaluatedSliQuery)
const dql=result.metadata.evaluatedSliQuery;
if (typeof dql !== "string") {
dql = String(dql);
}
// remove ONLY wrapping quotes
if (dql.startsWith('"') && dql.endsWith('"')) {
dql = dql.slice(1, -1);
}
return dql
}
Featured Posts