# Workflow automation

**URL:** <https://community.dynatrace.com/t/workflow-automation/45032>\
**Category:** Automations\
**Tags:** workflows, automations\
**Created:** [April 5, 2024, 5:43pm UTC](https://community.dynatrace.com/t/workflow-automation/45032 "2024-04-05T17:43:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahin24093](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@shahin24093](https://community.dynatrace.com/u/shahin24093)\
**Post date:** [April 5, 2024, 5:43pm UTC](https://community.dynatrace.com/t/workflow-automation/45032/1 "2024-04-05T17:43:22Z")

</div>

Hello Dynatrace family,

I have been having difficulty understanding how to interact with workflow tasks behavior and how to be able to control those behaviors.

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.

```auto
// 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);
}
}

```

How can I make this code to fail the task rather than successfully complete?

Edit: the content of driftResults is :

```auto
[
  {
    "errorid" : "6001"
  }
]

```

 ![result.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/8/8d0fe1eae372c3d09fea96c1b57542ca0d890ebf.jpeg)

---

<div class="post-metadata">

**Author:** ![Roberto\_Tonino](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/roberto_tonino/32/41817_2.png) [@Roberto\_Tonino](https://community.dynatrace.com/u/Roberto_Tonino)\
**Post date:** [April 16, 2024, 9:33am UTC](https://community.dynatrace.com/t/workflow-automation/45032/2 "2024-04-16T09:33:27Z")

</div>

Hi&nbsp;[@shahin24093](https://community.dynatrace.com/user/74298)&nbsp;,

you can throw the error in your catch block to make this work.

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”.

By re-throwing the error the action fails when checkIfSpecificerrorid throws. See here:

```javascript
// 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
  }
}

```

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:

 ![Screenshot 2024-04-16 at 11.32.14.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/4/e431694ef81a864481d82aab26b308b0ad07d7b4.png)
