Automations
All questions related to Workflow Automation, AutomationEngine, and EdgeConnect, as well as integrations with various tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Workflow

AntonioLara
Visitor
Hello, I have this workflow that runs every 5 minutes.
The first task is to perform a DQL query to retrieve the issues that have been active in the last 24 hours.The second task is to transform the JSON response into a table that is understandable and can be sent by email.This is where it fails.I've attached the workflow so you can guide me on how to send the results by email in a table format.

Thank you.

 

6 REPLIES 6

MaximilianoML
Champion

Hello @AntonioLara,

The important point here is that the Dynatrace Email action does not support HTML. It supports Markdown-style formatting, including tables, so the JavaScript task should return a Markdown table string, not an HTML table. Dynatrace documents that Email formatting supports tables, but HTML is not supported in the message body.

You can try to use this pattern:

import { result } from '@dynatrace-sdk/automation-utils';

export default async function () {
  // Replace this with the exact task name of your DQL task
  const dqlResult = await result('execute_dql_query');

  // Depending on the DQL task result shape, records may be in one of these locations
  const rows =
    dqlResult.records ??
    dqlResult.result?.records ??
    dqlResult.data ??
    [];

  if (!rows || rows.length === 0) {
    return {
      subject: 'Dynatrace issues report - no active issues',
      body: 'No issues were found in the last 24 hours.'
    };
  }

  const escapeCell = (value) => {
    if (value === null || value === undefined) {
      return '';
    }

    return String(value)
      .replace(/\|/g, '\\|')
      .replace(/\n/g, ' ');
  };

  const tableRows = rows.map((row) => {
    return [
      escapeCell(row['display_id'] ?? row['event.id'] ?? row['problem.id'] ?? ''),
      escapeCell(row['event.name'] ?? row['problem.title'] ?? row['title'] ?? ''),
      escapeCell(row['event.status'] ?? row['status'] ?? ''),
      escapeCell(row['dt.entity.host'] ?? row['dt.entity.service'] ?? row['entity'] ?? ''),
      escapeCell(row['timestamp'] ?? row['start_time'] ?? '')
    ].join(' | ');
  });

  const markdownTable = [
    '| ID | Title | Status | Entity | Time |',
    '|---|---|---|---|---|',
    ...tableRows.map((r) => `| ${r} |`)
  ].join('\n');

  return {
    subject: `Dynatrace issues report - ${rows.length} issue(s) in the last 24h`,
    body: `# Dynatrace issues report\n\nIssues detected in the last 24 hours:\n\n${markdownTable}`
  };
}

I hope this helps you 😁

 

Max Lopes

Hola

el resultado del correo se ve asi

AntonioLara_0-1778010083324.png

 

Hello @AntonioLara!

Yeah, because you're using the whole json object... you need to use only the Markdown part, so access the "body" and return the value (the markdown itself), you should be good to go. Let me know if it worked. P.s: If it helped you, please Kudo my replies, I'm aiming to be member of the month 😁

 

Max Lopes

The documentation is Here

Max Lopes

Excelent thanks

AntonioLara
Visitor

Is it possible to view this in a more understandable table format?

Featured Posts