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

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)

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:

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

Hi @r_weber

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 requestTimeoutMilliseconds , where you would wait x milliseconds for the query to be executed. That should do the trick in your case

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

An easier way to query data is ou use the useDqlQuery hook, Query and visualize Grail data | Dynatrace Developer

Best,
Sini

Thanks @sinisa_zubic ,

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.

The version with useDqlQuery crashes on me:

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)
}
An error occurred: {"code": 541, "message": "Execution crashed.", "details": {"type": "BAD_REQUEST", "message": "<stripped secret anyhow::Error>"}}

@r_weber 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.

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