# How do you get the result from queryExecutionClient.queryExecute()?

**URL:** <https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572>\
**Category:** Developer Q&A Forum\
**Tags:** workflows\
**Created:** [January 11, 2024, 5:05pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572 "2024-01-11T17:05:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [January 11, 2024, 5:05pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/1 "2024-01-11T17:05:29Z")

</div>

What is wrong with this code? It’s async, but shouldn’t there be something in result (I verfified that the executed query returns data)

```markup
async function getEntityName(entityId) {
  console.log(entityId)
  const eType = entityId.split('-')[0];
  console.log(eType);

  const query = 'fetch dt.entity.'+eType+' | filter id=="'+entityId+'"';
  console.log(query)
  const result = await queryExecutionClient.queryExecute({
    body: {
      query,
    }
  });
  console.log(result)
}

```

“result” just shows:

```markup
{
  result: undefined,
  ttlSeconds: 399,
  progress: undefined,
  requestToken: "jghsd2LVTPmQDTkWIl4QlQ==",
  state: "RUNNING"
}

```

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [January 11, 2024, 5:55pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/2 "2024-01-11T17:55:26Z")

</div>

Hi&nbsp;[@r\_weber](https://community.dynatrace.com/user/35901)

If you don’t add further props to the body, then this is expected behavior. you start a query and get as a result a request token you can use to poll for the result.

But as part of body, you can add another property&nbsp;requestTimeoutMilliseconds , where you would wait x milliseconds for the query to be executed. That should do the trick in your case

```markup
const result = await queryExecutionClient.queryExecute({
    body: {
      query,
      requestTimeoutMilliseconds: 30000
    }
  });

```

An easier way to query data is ou use the useDqlQuery hook,&nbsp;[Query and visualize Grail data | Dynatrace Developer](https://developer.dynatrace.com/develop/data/query-and-visualize/)

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [January 11, 2024, 6:39pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/3 "2024-01-11T18:39:12Z")

</div>

Thanks&nbsp;[@sinisa\_zubic](https://community.dynatrace.com/user/38283)&nbsp;,

the explicit addition of the requestTimeout should be documented and used in the examples!  
This seems to work, now…

Btw. I started with useDqlQuery hook, but since I saw the same behavior I gave the executionClient a try. I will try the hook again…lets see what happens.

---

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [January 11, 2024, 6:43pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/4 "2024-01-11T18:43:43Z")

</div>

The version with useDqlQuery crashes on me:

```markup
async function getEntityName(entityId) {
  console.log(entityId)
  const eType = entityId.split('-')[0];
  console.log(eType);

  const query = 'fetch dt.entity.'+eType+' | filter id=="'+entityId+'"';
  console.log(query)
  /*const result = await queryExecutionClient.queryExecute({
    body: {
      query,
      requestTimeoutMilliseconds: 30000
    }
  });
*/
  const result = useDqlQuery({
    body: {
      query,
    },
  });
  console.log(result)
}

```

```markup
An error occurred: {"code": 541, "message": "Execution crashed.", "details": {"type": "BAD_REQUEST", "message": "<stripped secret anyhow::Error>"}}

```

---

<div class="post-metadata">

**Author:** ![imsingh](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/imsingh/32/7858_2.png) [@imsingh](https://community.dynatrace.com/u/imsingh)\
**Post date:** [January 12, 2024, 12:50pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/5 "2024-01-12T12:50:39Z")

</div>

[@r\_weber](https://community.dynatrace.com/user/35901)&nbsp;are you using the hooks in app functions? Hooks can only be used in your react code. For all other places besides your react code, I’d suggest using `queryExecutionClient` instead.

---

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [January 14, 2024, 7:45pm UTC](https://community.dynatrace.com/t/how-do-you-get-the-result-from-queryexecutionclient-queryexecute/43572/6 "2024-01-14T19:45:32Z")

</div>

OK, that wasn’t clear. I tried to use it in a workflow.
