# How to record the result from a DQL query and modify the output

**URL:** <https://community.dynatrace.com/t/how-to-record-the-result-from-a-dql-query-and-modify-the-output/51509>\
**Category:** Automations\
**Tags:** dql, workflows\
**Created:** [May 6, 2025, 6:48pm UTC](https://community.dynatrace.com/t/how-to-record-the-result-from-a-dql-query-and-modify-the-output/51509 "2025-05-06T18:48:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaladhar](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Kaladhar](https://community.dynatrace.com/u/Kaladhar)\
**Post date:** [May 6, 2025, 6:48pm UTC](https://community.dynatrace.com/t/how-to-record-the-result-from-a-dql-query-and-modify-the-output/51509/1 "2025-05-06T18:48:21Z")

</div>

Hello Everyone,

I am trying to record content from the result/output of the previous DQL query so that I can modify the output.

**Example:**

DQL query:

_timeseries { count(`metric-A`), value.A = avg(`metric-A`, scalar: true) }, by: { message\_vpn\_name, client\_user\_name }, filter: { NOT matchesValue(client\_user\_name, “X=xyz.abc”) AND NOT matchesValue(client\_user\_name, “\*12345\*”) }_

Sample Output in table format:

**VPN&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;client\_user\_name**

EFGHI&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[def-sit.com](http://def-sit.com)

JIKOL&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;[def-int.com](http://def-int.com)

etc…

Now I want to record this output and then remove everything from ‘-’ in the output (ex:&nbsp;-sit.com,&nbsp;-int.com, etc).

I tried using “data record(content” metric command and then string function “replaceString” to modify the output which is not working.

Please suggest the right the metric command and string function or for loop if possible.

Thanks,

---

<div class="post-metadata">

**Author:** ![ChristopherHejl](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christopherhejl/32/20735_2.png) [@ChristopherHejl](https://community.dynatrace.com/u/ChristopherHejl)\
**Post date:** [May 7, 2025, 8:09am UTC](https://community.dynatrace.com/t/how-to-record-the-result-from-a-dql-query-and-modify-the-output/51509/2 "2025-05-07T08:09:55Z")

</div>

ReplaceString requires an exact string. You can either try to make a pattern and use replacePattern or split the string based on the “-”.  
One example I came up with (using cpu metric as an example)  
client\_user\_name\_adjusted field will have the value of any “k8s.node.name” which comes before the first “-”:

```markup
timeseries { avg(dt.host.cpu.user), value.A = avg(dt.host.cpu.user, scalar: true) }, by: { k8s.node.name, host.name }
| fieldsAdd client_user_name_adjusted = splitString(k8s.node.name, "-")[0]

```

---

<div class="post-metadata">

**Author:** ![Kaladhar](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Kaladhar](https://community.dynatrace.com/u/Kaladhar)\
**Post date:** [May 7, 2025, 11:27am UTC](https://community.dynatrace.com/t/how-to-record-the-result-from-a-dql-query-and-modify-the-output/51509/3 "2025-05-07T11:27:42Z")

</div>

This looks great. Thanks for the quick response.

I just want to update that another string function substring(xyz\_abc\_123, from: 0, to: 3) does the work for me.
