# Dashboard tip: Combine DQL with a REST call in one Dashboard

**URL:** <https://community.dynatrace.com/t/dashboard-tip-combine-dql-with-a-rest-call-in-one-dashboard/50039>\
**Category:** Dynatrace Tips\
**Tags:** timeframe, dashboards\
**Created:** [February 2, 2025, 11:09am UTC](https://community.dynatrace.com/t/dashboard-tip-combine-dql-with-a-rest-call-in-one-dashboard/50039 "2025-02-02T11:09:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [February 2, 2025, 11:09am UTC](https://community.dynatrace.com/t/dashboard-tip-combine-dql-with-a-rest-call-in-one-dashboard/50039/1 "2025-02-02T11:09:55Z")

</div>

Hello,

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&nbsp; ID’s based on the that name.

 ![henk_stobbe_0-1738494355633.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/2/5229697ebc0e84e80da2324bc6026f32d50be654.png)

Maybe it can give someone some inspiration (-;

Source will be in the reply, you need to add ServiceNow url and token, I love comments and remarks,

KR Henk

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [February 2, 2025, 11:14am UTC](https://community.dynatrace.com/t/dashboard-tip-combine-dql-with-a-rest-call-in-one-dashboard/50039/2 "2025-02-02T11:14:58Z")

</div>

import { queryExecutionClient } from ‘@dynatrace-sdk/client-query’;  
export default async function () {  
function delay(ms) {  
return new Promise(resolve =\> setTimeout(resolve, ms));  
}  
function removeMilliseconds(isoString) {  
const date = new Date(isoString);  
return date.toISOString().split(‘.’)[0] + ‘Z’;  
}  
const from = removeMilliseconds($dt\_timeframe\_from);  
const to = removeMilliseconds($dt\_timeframe\_to);

// DQL fetching all hosts in Dt  
const data = await queryExecutionClient.queryExecute({  
body: {  
query: `fetch dt.entity.host,timeframe: “${from}/${to}”`  
}  
});

let result;  
// Wait for DQL to finish  
while (true) {  
result = await queryExecutionClient.queryPoll({  
requestToken: data.requestToken  
});

if (result.state !== “RUNNING”) {  
break;  
}

// Wait for 1 second before polling again  
await delay(1000);  
}

// Check if result.result.records exists and is an array  
if (result && result.result && Array.isArray(result.result.records)) {  
// Extract entity names from the result  
const entityNames = result.result.records.map(record =\> record[‘entity.name’]);

// Create an array to hold the final results  
const finalResults = [];  
const requestOptions = {  
method: “GET”,  
headers: {  
“Accept”: “application/json”,  
“Authorization”: “Basic Pleasaddyourowntokenhere”  
}  
};

// Iterate over each entity name and find the corresponding value in SNOW  
for (const entityName of entityNames) {  
try {  
// Sending the request using fetch  
const response = await fetch(`[https://please.use.your.snow.url/api/now/table/cmdb\_ci?sysparm\_fields=u\_number&sysparm\_query=company.sys\_id=UseYourSysIDifNeeded&name=${encodeURIComponent(entityName)}\`](https://please.use.your.snow.url/api/now/table/cmdb_ci?sysparm_fields=u_number&sysparm_query=company.sys_id=UseYourSysIDifNeeded&name=$%7BencodeURIComponent(entityName)%7D%5C%60), requestOptions);  
const data = await response.json(); // Expecting JSON response

const values = data.result.map(item =\> item.u\_number);

if (values.length === 0) {  
finalResults.push({ DynatraceHost: entityName, ServiceNowID: ‘no records found’ });  
} else if (values.length === 1) {  
finalResults.push({ DynatraceHost: entityName, ServiceNowID: values[0] });  
} else {  
finalResults.push({ DynatraceHost: entityName, ServiceNowID: ‘multiple recodrs found’ });  
}  
} catch (error) {  
console.error(`Error fetching data for ${entityName}:`, error);  
finalResults.push({ DynatraceHost: entityName, ServiceNowID: ‘error fetching data’ });  
}  
}

return finalResults;  
} else {  
throw new Error(‘No records found in the result.’);  
}  
}
