<?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: Dashboard tip, combine DQL (with  time selector) with a REST call in one Dashboard  ***almost an app (-;*** in Dynatrace tips</title>
    <link>https://community.dynatrace.com/t5/Dynatrace-tips/Dashboard-tip-Combine-DQL-with-a-REST-call-in-one-Dashboard/m-p/268978#M1815</link>
    <description>&lt;P&gt;import { queryExecutionClient } from '@dynatrace-sdk/client-query';&lt;BR /&gt;export default async function () {&lt;BR /&gt;function delay(ms) {&lt;BR /&gt;return new Promise(resolve =&amp;gt; setTimeout(resolve, ms));&lt;BR /&gt;}&lt;BR /&gt;function removeMilliseconds(isoString) {&lt;BR /&gt;const date = new Date(isoString);&lt;BR /&gt;return date.toISOString().split('.')[0] + 'Z';&lt;BR /&gt;}&lt;BR /&gt;const from = removeMilliseconds($dt_timeframe_from);&lt;BR /&gt;const to = removeMilliseconds($dt_timeframe_to);&lt;/P&gt;&lt;P&gt;// DQL fetching all hosts in Dt&lt;BR /&gt;const data = await queryExecutionClient.queryExecute({&lt;BR /&gt;body: {&lt;BR /&gt;query: `fetch dt.entity.host,timeframe: "${from}/${to}"`&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;let result;&lt;BR /&gt;// Wait for DQL to finish&lt;BR /&gt;while (true) {&lt;BR /&gt;result = await queryExecutionClient.queryPoll({&lt;BR /&gt;requestToken: data.requestToken&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (result.state !== "RUNNING") {&lt;BR /&gt;break;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Wait for 1 second before polling again&lt;BR /&gt;await delay(1000);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Check if result.result.records exists and is an array&lt;BR /&gt;if (result &amp;amp;&amp;amp; result.result &amp;amp;&amp;amp; Array.isArray(result.result.records)) {&lt;BR /&gt;// Extract entity names from the result&lt;BR /&gt;const entityNames = result.result.records.map(record =&amp;gt; record['entity.name']);&lt;/P&gt;&lt;P&gt;// Create an array to hold the final results&lt;BR /&gt;const finalResults = [];&lt;BR /&gt;const requestOptions = {&lt;BR /&gt;method: "GET",&lt;BR /&gt;headers: {&lt;BR /&gt;"Accept": "application/json",&lt;BR /&gt;"Authorization": "Basic Pleasaddyourowntokenhere"&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;// Iterate over each entity name and find the corresponding value in SNOW&lt;BR /&gt;for (const entityName of entityNames) {&lt;BR /&gt;try {&lt;BR /&gt;// Sending the request using fetch&lt;BR /&gt;const response = await fetch(`&lt;A href="https://please.use.your.snow.url/api/now/table/cmdb_ci?sysparm_fields=u_number&amp;amp;sysparm_query=company.sys_id=UseYourSysIDifNeeded&amp;amp;name=${encodeURIComponent(entityName" target="_blank"&gt;https://please.use.your.snow.url/api/now/table/cmdb_ci?sysparm_fields=u_number&amp;amp;sysparm_query=company.sys_id=UseYourSysIDifNeeded&amp;amp;name=${encodeURIComponent(entityName&lt;/A&gt;)}`, requestOptions);&lt;BR /&gt;const data = await response.json(); // Expecting JSON response&lt;/P&gt;&lt;P&gt;const values = data.result.map(item =&amp;gt; item.u_number);&lt;/P&gt;&lt;P&gt;if (values.length === 0) {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'no records found' });&lt;BR /&gt;} else if (values.length === 1) {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: values[0] });&lt;BR /&gt;} else {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'multiple recodrs found' });&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(`Error fetching data for ${entityName}:`, error);&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'error fetching data' });&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return finalResults;&lt;BR /&gt;} else {&lt;BR /&gt;throw new Error('No records found in the result.');&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Sun, 02 Feb 2025 11:14:58 GMT</pubDate>
    <dc:creator>henk_stobbe</dc:creator>
    <dc:date>2025-02-02T11:14:58Z</dc:date>
    <item>
      <title>Dashboard tip: Combine DQL with a REST call in one Dashboard</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-tips/Dashboard-tip-Combine-DQL-with-a-REST-call-in-one-Dashboard/m-p/268977#M1814</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;As an example I have created a Dashboard that retrieves all host names from Dynatrace, using the current time selector. And based on these results asks ServiceNow to return the&amp;nbsp; ID's based on the that name.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="henk_stobbe_0-1738494355633.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/26125i483056C1F9E702C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="henk_stobbe_0-1738494355633.png" alt="henk_stobbe_0-1738494355633.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Maybe it can give someone some inspiration (-;&lt;/P&gt;
&lt;P&gt;Source will be in the reply, you need to add ServiceNow url and token, I love comments and remarks,&lt;/P&gt;
&lt;P&gt;KR Henk&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2025 10:55:27 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-tips/Dashboard-tip-Combine-DQL-with-a-REST-call-in-one-Dashboard/m-p/268977#M1814</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2025-12-05T10:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard tip, combine DQL (with  time selector) with a REST call in one Dashboard  ***almost an app (-;***</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-tips/Dashboard-tip-Combine-DQL-with-a-REST-call-in-one-Dashboard/m-p/268978#M1815</link>
      <description>&lt;P&gt;import { queryExecutionClient } from '@dynatrace-sdk/client-query';&lt;BR /&gt;export default async function () {&lt;BR /&gt;function delay(ms) {&lt;BR /&gt;return new Promise(resolve =&amp;gt; setTimeout(resolve, ms));&lt;BR /&gt;}&lt;BR /&gt;function removeMilliseconds(isoString) {&lt;BR /&gt;const date = new Date(isoString);&lt;BR /&gt;return date.toISOString().split('.')[0] + 'Z';&lt;BR /&gt;}&lt;BR /&gt;const from = removeMilliseconds($dt_timeframe_from);&lt;BR /&gt;const to = removeMilliseconds($dt_timeframe_to);&lt;/P&gt;&lt;P&gt;// DQL fetching all hosts in Dt&lt;BR /&gt;const data = await queryExecutionClient.queryExecute({&lt;BR /&gt;body: {&lt;BR /&gt;query: `fetch dt.entity.host,timeframe: "${from}/${to}"`&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;let result;&lt;BR /&gt;// Wait for DQL to finish&lt;BR /&gt;while (true) {&lt;BR /&gt;result = await queryExecutionClient.queryPoll({&lt;BR /&gt;requestToken: data.requestToken&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;if (result.state !== "RUNNING") {&lt;BR /&gt;break;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Wait for 1 second before polling again&lt;BR /&gt;await delay(1000);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Check if result.result.records exists and is an array&lt;BR /&gt;if (result &amp;amp;&amp;amp; result.result &amp;amp;&amp;amp; Array.isArray(result.result.records)) {&lt;BR /&gt;// Extract entity names from the result&lt;BR /&gt;const entityNames = result.result.records.map(record =&amp;gt; record['entity.name']);&lt;/P&gt;&lt;P&gt;// Create an array to hold the final results&lt;BR /&gt;const finalResults = [];&lt;BR /&gt;const requestOptions = {&lt;BR /&gt;method: "GET",&lt;BR /&gt;headers: {&lt;BR /&gt;"Accept": "application/json",&lt;BR /&gt;"Authorization": "Basic Pleasaddyourowntokenhere"&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;// Iterate over each entity name and find the corresponding value in SNOW&lt;BR /&gt;for (const entityName of entityNames) {&lt;BR /&gt;try {&lt;BR /&gt;// Sending the request using fetch&lt;BR /&gt;const response = await fetch(`&lt;A href="https://please.use.your.snow.url/api/now/table/cmdb_ci?sysparm_fields=u_number&amp;amp;sysparm_query=company.sys_id=UseYourSysIDifNeeded&amp;amp;name=${encodeURIComponent(entityName" target="_blank"&gt;https://please.use.your.snow.url/api/now/table/cmdb_ci?sysparm_fields=u_number&amp;amp;sysparm_query=company.sys_id=UseYourSysIDifNeeded&amp;amp;name=${encodeURIComponent(entityName&lt;/A&gt;)}`, requestOptions);&lt;BR /&gt;const data = await response.json(); // Expecting JSON response&lt;/P&gt;&lt;P&gt;const values = data.result.map(item =&amp;gt; item.u_number);&lt;/P&gt;&lt;P&gt;if (values.length === 0) {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'no records found' });&lt;BR /&gt;} else if (values.length === 1) {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: values[0] });&lt;BR /&gt;} else {&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'multiple recodrs found' });&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(`Error fetching data for ${entityName}:`, error);&lt;BR /&gt;finalResults.push({ DynatraceHost: entityName, ServiceNowID: 'error fetching data' });&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return finalResults;&lt;BR /&gt;} else {&lt;BR /&gt;throw new Error('No records found in the result.');&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2025 11:14:58 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-tips/Dashboard-tip-Combine-DQL-with-a-REST-call-in-one-Dashboard/m-p/268978#M1815</guid>
      <dc:creator>henk_stobbe</dc:creator>
      <dc:date>2025-02-02T11:14:58Z</dc:date>
    </item>
  </channel>
</rss>

