<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set DQL Query in Dashboard Variable in Dashboarding</title>
    <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300100#M5811</link>
    <description>&lt;P&gt;Thanks, since this is running in a Dashboard Code tile, I would first check how &lt;STRONG&gt;$sliQuery&lt;/STRONG&gt; is defined at the dashboard level.&lt;/P&gt;&lt;P&gt;Could you share the configuration of the &lt;STRONG&gt;sliQuery&lt;/STRONG&gt;&amp;nbsp;dashboard variable?&lt;/P&gt;&lt;P&gt;Mainly:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Variable name:&lt;/LI&gt;&lt;LI&gt;Variable type:&lt;/LI&gt;&lt;LI&gt;Variable source/query:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Returned value:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is the variable returning the full DQL query as text, or only an SLO ID/name?&lt;/LI&gt;&lt;LI&gt;Is the variable single-select or multi-select?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So the next thing to confirm is whether &lt;STRONG&gt;sliQuery&lt;/STRONG&gt; is really configured as a dashboard variable and whether the variable name matches exactly. For example, if the variable is named &lt;STRONG&gt;SliQuery&lt;/STRONG&gt;, &lt;STRONG&gt;sli_query&lt;/STRONG&gt;, or sliQuery, the reference needs to match the supported dashboard variable syntax exactly.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2026 15:58:14 GMT</pubDate>
    <dc:creator>MaximilianoML</dc:creator>
    <dc:date>2026-05-29T15:58:14Z</dc:date>
    <item>
      <title>Set DQL Query in Dashboard Variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300094#M5808</link>
      <description>&lt;P&gt;I am attempting to build my own custom SLO dashboard using the Grail SLOs we have defined in our environment.&amp;nbsp; I am able to successfully query the SLO list using javascript and I can list out the metadata found on the SLOs.&amp;nbsp; One piece of information is the DQL that is used to build the SLI data and generate the SLO.&amp;nbsp; I want to capture that query, set it as a dashboard variable and then run that query on another panel.&amp;nbsp; So far I have been unsuccessful on the last part, running the query on a separate panel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 13:27:02 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300094#M5808</guid>
      <dc:creator>gdalessandro</dc:creator>
      <dc:date>2026-05-29T13:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Set DQL Query in Dashboard Variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300096#M5809</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/74173"&gt;@gdalessandro&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I think the limitation here is how dashboard variables work.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;So something like this usually will not work:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$SloQuery&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Even with options like :noquote, the variable is still value substitution, not dynamic DQL execution.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 13:44:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300096#M5809</guid>
      <dc:creator>MaximilianoML</dc:creator>
      <dc:date>2026-05-29T13:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Set DQL Query in Dashboard Variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300099#M5810</link>
      <description>&lt;P&gt;I am doing this in a code tile and it is still failing for the same reasons you describe above.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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 &amp;amp;&amp;amp; data.result.records) {
            console.log("Query Results:");
            data.result.records.forEach((row, idx) =&amp;gt; {
                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();&lt;/LI-CODE&gt;&lt;P&gt;{&lt;BR /&gt;"error": {&lt;BR /&gt;"code": 540,&lt;BR /&gt;"message": "Execution crashed.",&lt;BR /&gt;"details": {&lt;BR /&gt;"logs": "ReferenceError: $sliQuery is not defined\n at runDqlQuery (file:///script.ts:9:17)\n at file:///script.ts:57:1\n",&lt;BR /&gt;"type": "UNCAUGHT_EXCEPTION",&lt;BR /&gt;"message": "Uncaught (in promise) ReferenceError: $sliQuery is not defined",&lt;BR /&gt;"details": {&lt;BR /&gt;"sourceLine": " const query = $sliQuery ;",&lt;BR /&gt;"lineNumber": 9,&lt;BR /&gt;"startColumn": 17,&lt;BR /&gt;"stack": "ReferenceError: $sliQuery is not defined\n at runDqlQuery (file:///script.ts:9:17)\n at file:///script.ts:57:1"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 15:48:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300099#M5810</guid>
      <dc:creator>gdalessandro</dc:creator>
      <dc:date>2026-05-29T15:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Set DQL Query in Dashboard Variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300100#M5811</link>
      <description>&lt;P&gt;Thanks, since this is running in a Dashboard Code tile, I would first check how &lt;STRONG&gt;$sliQuery&lt;/STRONG&gt; is defined at the dashboard level.&lt;/P&gt;&lt;P&gt;Could you share the configuration of the &lt;STRONG&gt;sliQuery&lt;/STRONG&gt;&amp;nbsp;dashboard variable?&lt;/P&gt;&lt;P&gt;Mainly:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Variable name:&lt;/LI&gt;&lt;LI&gt;Variable type:&lt;/LI&gt;&lt;LI&gt;Variable source/query:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Returned value:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is the variable returning the full DQL query as text, or only an SLO ID/name?&lt;/LI&gt;&lt;LI&gt;Is the variable single-select or multi-select?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So the next thing to confirm is whether &lt;STRONG&gt;sliQuery&lt;/STRONG&gt; is really configured as a dashboard variable and whether the variable name matches exactly. For example, if the variable is named &lt;STRONG&gt;SliQuery&lt;/STRONG&gt;, &lt;STRONG&gt;sli_query&lt;/STRONG&gt;, or sliQuery, the reference needs to match the supported dashboard variable syntax exactly.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 15:58:14 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300100#M5811</guid>
      <dc:creator>MaximilianoML</dc:creator>
      <dc:date>2026-05-29T15:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Set DQL Query in Dashboard Variable</title>
      <link>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300101#M5812</link>
      <description>&lt;P&gt;variable name: sliQuery&lt;/P&gt;&lt;P&gt;Multiselect (default value is *)&lt;BR /&gt;value returned when using console.log in the javascript for the variable:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*
* 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('"') &amp;amp;&amp;amp; dql.endsWith('"')) {
  dql = dql.slice(1, -1);
}

  return dql
 
 
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 May 2026 17:03:23 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dashboarding/Set-DQL-Query-in-Dashboard-Variable/m-p/300101#M5812</guid>
      <dc:creator>gdalessandro</dc:creator>
      <dc:date>2026-05-29T17:03:23Z</dc:date>
    </item>
  </channel>
</rss>

