<?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: Looping through items in a collection of records - Workflows in Automations</title>
    <link>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249402#M1652</link>
    <description>&lt;P&gt;You can use a for loop in any input (with the exception of javascript task, there you would natively loop) in order to generate the message. Here would be an example with the data you provided:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;Here is the email.

You can use for expressions as well as if/else or any combination.

Host utilization summary:
{% for record in result("get_disk_stats")["records"] %}
	- {{ record["Host"] }}: {{ record["util"] }}
{% endfor %}

You can also use other expressions at any place.
Eg scanned bytes: {{ result("get_disk_stats")["metadata"]["grail"]["scannedBytes"] }}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChristopherHejl_1-1719578336007.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/20834i268CEB40FA083985/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChristopherHejl_1-1719578336007.png" alt="ChristopherHejl_1-1719578336007.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 12:39:12 GMT</pubDate>
    <dc:creator>ChristopherHejl</dc:creator>
    <dc:date>2024-06-28T12:39:12Z</dc:date>
    <item>
      <title>Looping through items in a collection of records - Workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249397#M1650</link>
      <description>&lt;P&gt;What I need is to loop through all of the records from a DQL output and have it formatted in a human-readable format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my DQL query&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries percent = avg(dt.host.disk.used.percent), by: { dt.entity.host, dt.entity.disk }, filter: { in(dt.entity.host, classicEntitySelector("type(host),tag(\"Business Unit:FINANCE\")")) }
| fields util = abs(arrayAvg(percent)), entityName(dt.entity.host)
| fieldsRename dt.entity.host.name, Host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...which if I use get_disk_stats.records, equivalent to {{ result("get_disk_stats")["records"] }}, I get the following output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "Host": "WIN11023.corporate.org",
    "util": 73.14564947430772
  },
  {
    "Host": "WIN19876.corporate.org",
    "util": 49.68959838117046
  },
  {
    "Host": "WIN11234.corporate.org",
    "util": 37.80735823445836
  },
  {
    "Host": "WIN15678.corporate.org",
    "util": 69.33072939353247
  },
  {
    "Host": "WIN19987.corporate.org",
    "util": 37.659657944489574
  },
  {
    "Host": "WIN12045.corporate.org",
    "util": 42.12913605995685
  },
  {
    "Host": "WIN13456.corporate.org",
    "util": 0.5479891637632675
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I code the for loop within the input itself or in the 'Options' menu?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 12:14:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249397#M1650</guid>
      <dc:creator>badgerfifteen</dc:creator>
      <dc:date>2024-06-28T12:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through items in a collection of records - Workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249402#M1652</link>
      <description>&lt;P&gt;You can use a for loop in any input (with the exception of javascript task, there you would natively loop) in order to generate the message. Here would be an example with the data you provided:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;Here is the email.

You can use for expressions as well as if/else or any combination.

Host utilization summary:
{% for record in result("get_disk_stats")["records"] %}
	- {{ record["Host"] }}: {{ record["util"] }}
{% endfor %}

You can also use other expressions at any place.
Eg scanned bytes: {{ result("get_disk_stats")["metadata"]["grail"]["scannedBytes"] }}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChristopherHejl_1-1719578336007.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/20834i268CEB40FA083985/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChristopherHejl_1-1719578336007.png" alt="ChristopherHejl_1-1719578336007.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 12:39:12 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249402#M1652</guid>
      <dc:creator>ChristopherHejl</dc:creator>
      <dc:date>2024-06-28T12:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through items in a collection of records - Workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249410#M1653</link>
      <description>&lt;P&gt;absolute genius, thank you so much! Have a good weekend! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 13:38:52 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Looping-through-items-in-a-collection-of-records-Workflows/m-p/249410#M1653</guid>
      <dc:creator>badgerfifteen</dc:creator>
      <dc:date>2024-06-28T13:38:52Z</dc:date>
    </item>
  </channel>
</rss>

