<?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 Workflow automation in Automations</title>
    <link>https://community.dynatrace.com/t5/Automations/Workflow-automation/m-p/242002#M1528</link>
    <description>&lt;P&gt;Hello Dynatrace family,&lt;/P&gt;&lt;P&gt;I have been having difficulty understanding how to interact with workflow tasks behavior and how to be able to control those behaviors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a javascript code that checks if a variable that I captured from previous task matches it or not, if it doesn't match I want my task to fail but It always ends up being successful even when the value doesn't match with what I defined.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// optional import of sdk modules&lt;BR /&gt;import { execution } from '@dynatrace-sdk/automation-utils';&lt;BR /&gt;import { executionsClient } from '@dynatrace-sdk/client-automation';&lt;BR /&gt;&lt;BR /&gt;export default async function ({ execution_id }) {&lt;BR /&gt;const ex = await execution(execution_id);&lt;BR /&gt;var results:JSON = await executionsClient.getTaskExecutionResult({ executionId: execution_id, id: "execute_dql_query_1" });&lt;BR /&gt;var driftResults = results.records;&lt;BR /&gt;let errorIdValue = driftResults[0].errorid;&lt;BR /&gt;function checkIfSpecificerrorid(value) {&lt;BR /&gt;const specificNumber = 6000;&lt;BR /&gt;const numericValue = Number(value);&lt;BR /&gt;&lt;BR /&gt;if (numericValue !== specificNumber){&lt;BR /&gt;throw new Error("Value does not match " + specificNumber);&lt;BR /&gt;} &lt;BR /&gt;console.log("value matches the specific number: " + value);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;try {&lt;BR /&gt;if (errorIdValue !== undefined) {&lt;BR /&gt;checkIfSpecificerrorid(errorIdValue);&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(error.message);&lt;BR /&gt;}&lt;BR /&gt;}&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;How can I make this code to fail the task rather than successfully complete?&lt;BR /&gt;&lt;BR /&gt;Edit: the content of&amp;nbsp;driftResults is :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[&lt;BR /&gt;  {&lt;BR /&gt;    "errorid" : "6001"&lt;BR /&gt;  }&lt;BR /&gt;]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2024 17:51:57 GMT</pubDate>
    <dc:creator>shahin24093</dc:creator>
    <dc:date>2024-04-05T17:51:57Z</dc:date>
    <item>
      <title>Workflow automation</title>
      <link>https://community.dynatrace.com/t5/Automations/Workflow-automation/m-p/242002#M1528</link>
      <description>&lt;P&gt;Hello Dynatrace family,&lt;/P&gt;&lt;P&gt;I have been having difficulty understanding how to interact with workflow tasks behavior and how to be able to control those behaviors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a javascript code that checks if a variable that I captured from previous task matches it or not, if it doesn't match I want my task to fail but It always ends up being successful even when the value doesn't match with what I defined.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// optional import of sdk modules&lt;BR /&gt;import { execution } from '@dynatrace-sdk/automation-utils';&lt;BR /&gt;import { executionsClient } from '@dynatrace-sdk/client-automation';&lt;BR /&gt;&lt;BR /&gt;export default async function ({ execution_id }) {&lt;BR /&gt;const ex = await execution(execution_id);&lt;BR /&gt;var results:JSON = await executionsClient.getTaskExecutionResult({ executionId: execution_id, id: "execute_dql_query_1" });&lt;BR /&gt;var driftResults = results.records;&lt;BR /&gt;let errorIdValue = driftResults[0].errorid;&lt;BR /&gt;function checkIfSpecificerrorid(value) {&lt;BR /&gt;const specificNumber = 6000;&lt;BR /&gt;const numericValue = Number(value);&lt;BR /&gt;&lt;BR /&gt;if (numericValue !== specificNumber){&lt;BR /&gt;throw new Error("Value does not match " + specificNumber);&lt;BR /&gt;} &lt;BR /&gt;console.log("value matches the specific number: " + value);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;try {&lt;BR /&gt;if (errorIdValue !== undefined) {&lt;BR /&gt;checkIfSpecificerrorid(errorIdValue);&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(error.message);&lt;BR /&gt;}&lt;BR /&gt;}&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;How can I make this code to fail the task rather than successfully complete?&lt;BR /&gt;&lt;BR /&gt;Edit: the content of&amp;nbsp;driftResults is :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[&lt;BR /&gt;  {&lt;BR /&gt;    "errorid" : "6001"&lt;BR /&gt;  }&lt;BR /&gt;]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 17:51:57 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Workflow-automation/m-p/242002#M1528</guid>
      <dc:creator>shahin24093</dc:creator>
      <dc:date>2024-04-05T17:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Workflow automation</title>
      <link>https://community.dynatrace.com/t5/Automations/Workflow-automation/m-p/242713#M1543</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/74298"&gt;@shahin24093&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;you can throw the error in your catch block to make this work.&lt;BR /&gt;&lt;BR /&gt;By having a catch block, you are telling JavaScript "hey, if there is an error thrown in checkIfSpecificerrorid let me (the person who is writing the code) handle it, don't fail the action".&lt;BR /&gt;&lt;BR /&gt;By re-throwing the error the action fails when checkIfSpecificerrorid throws. See here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// optional import of sdk modules
import { execution } from '@dynatrace-sdk/automation-utils';
import { executionsClient } from '@dynatrace-sdk/client-automation';

export default async function ({ execution_id }) {
  const ex = await execution(execution_id);
  var results: JSON = await executionsClient.getTaskExecutionResult({ executionId: execution_id, id: "execute_dql_query_1" });
  var driftResults = results.records;
  let errorIdValue = driftResults[0].errorid;

  function checkIfSpecificerrorid(value) {
    const specificNumber = 6000;
    const numericValue = Number(value);

    if (numericValue !== specificNumber) {
      throw new Error("Value does not match " + specificNumber);
    }
    console.log("value matches the specific number: " + value);
  }

  try {
    if (errorIdValue !== undefined) {
      checkIfSpecificerrorid(errorIdValue);
    }
  } catch (error) {
    console.error(error.message);
    throw error
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note the "throw error" line after the "console.error(error)" line. With this you will get the action to fail. The output will be the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-04-16 at 11.32.14.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/18913i077179B308AD50E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-04-16 at 11.32.14.png" alt="Screenshot 2024-04-16 at 11.32.14.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 09:35:06 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Workflow-automation/m-p/242713#M1543</guid>
      <dc:creator>Roberto_Tonino</dc:creator>
      <dc:date>2024-04-16T09:35:06Z</dc:date>
    </item>
  </channel>
</rss>

