# Build workflow to send SMS notification for problems detected after business hours

**URL:** <https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552>\
**Category:** DQL\
**Tags:** dql, platform-notifications, workflows\
**Created:** [March 11, 2024, 12:29pm UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552 "2024-03-11T12:29:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omkar\_B](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/omkar_b/32/7148_2.png) [@Omkar\_B](https://community.dynatrace.com/u/Omkar_B)\
**Post date:** [March 11, 2024, 12:29pm UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/1 "2024-03-11T12:29:19Z")

</div>

Hello Team,  
Can someone help me to build workflow for below use case :

We want Dynatrace to send SMS notification for problems generated between 18:00 To 06:00(nextDay) monday to friday if the impacted entity falls under sev1 or sev2 category.  
I am using Problem based trigger and need help to build query to filter problem where time stamp is after 18:00 or before 06:00 and day is between Monday to Friday.

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [March 11, 2024, 2:46pm UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/2 "2024-03-11T14:46:50Z")

</div>

hi

Try your DQL with

```php
| fieldsAdd day_of_week = getDayOfWeek(timestamp), hour_of_day = getHour(timestamp)
| filter (hour_of_day > 18 OR hour_of_day < 6) AND day_of_week >= 1 AND day_of_week <= 5

```

---

<div class="post-metadata">

**Author:** ![Omkar\_B](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/omkar_b/32/7148_2.png) [@Omkar\_B](https://community.dynatrace.com/u/Omkar_B)\
**Post date:** [March 11, 2024, 5:18pm UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/3 "2024-03-11T17:18:48Z")

</div>

Hello&nbsp;[@PacoPorro](https://community.dynatrace.com/user/40713),

I have DQL query to fetch events with this filter but can I trigger workflow using this ? if yes, How ?  
Do you know how can we use match phrase function in workflow ?

Thanks

---

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [March 12, 2024, 3:29am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/4 "2024-03-12T03:29:15Z")

</div>

Hi&nbsp;[@Omkar\_B](https://community.dynatrace.com/user/41304)

**You can achieve this in 3 steps:**

1. Set the trigger to every morning at 9 AM (for example)
2. In 2nd step add Task to execute JavaScript code. In the code you have to call APIs to fetch the problems that has come after 18:00 and within 06:00 and from their you can get the problems that has higher severity. You get the JSON as an output and that can be fed to the next step.
3. In the 3rd step you can use HTTP request and configure your result in such a way that in will be sent to the person based on the web hook you get from the customer and respective headers for it.

**Note:** You have to reconfigure your JSON output in 2nd step itself so that SMS messages will not be split in the 3rd step.

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [March 12, 2024, 11:42am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/5 "2024-03-12T11:42:56Z")

</div>

Use a cron trigger in the workflow as step 1, run the dql as step 2, run the SMS http request as step 3

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [March 12, 2024, 11:50am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/6 "2024-03-12T11:50:15Z")

</div>

Just tested the filter option, and seems to be working:

```php
(getHour(timestamp) > 18 OR getHour(timestamp) < 6) AND getDayOfWeek(timestamp) >= 1 AND getDayOfWeek(timestamp) <= 5

```

 ![PacoPorro_0-1710244167210.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/114a167464d9196b17c183d85dc1ced0225f673e.png)

---

<div class="post-metadata">

**Author:** ![Omkar\_B](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/omkar_b/32/7148_2.png) [@Omkar\_B](https://community.dynatrace.com/u/Omkar_B)\
**Post date:** [March 12, 2024, 11:52am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/7 "2024-03-12T11:52:35Z")

</div>

[@theharithsa](https://community.dynatrace.com/user/39872)&nbsp;  
Why do we need to pull data via API if it is available in workflow or DQL. Can’t we use those available options to achieve this ?

---

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [March 18, 2024, 2:31am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/8 "2024-03-18T02:31:11Z")

</div>

You can use both, but you can’t use Davis problem trigger as a task. For that, you’ll need to run some JavaScript. There’s a library that can fetch problems in the same tenant.

---

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [March 18, 2024, 2:32am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/9 "2024-03-18T02:32:46Z")

</div>

It is good to get the problems. Thanks [@PacoPorro](https://community.dynatrace.com/user/40713)

Is this what you were looking for [@Omkar\_B](https://community.dynatrace.com/user/41304)?

---

<div class="post-metadata">

**Author:** ![Omkar\_B](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/omkar_b/32/7148_2.png) [@Omkar\_B](https://community.dynatrace.com/u/Omkar_B)\
**Post date:** [April 11, 2024, 8:13am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/10 "2024-04-11T08:13:43Z")

</div>

Just wanted to share approach I used to achieve this -&nbsp;  
1. Used Davis Problem Trigger for problems in Open or Closed state and having certain conditions like tag=“abc”.  
2. Task (JavaScript) to get output of trigger check conditions for time like hour after 6 PM and weekday or weekend and call SMS API if conditions are matching.

There are some SDKs available to get data of trigger or previous which we can use during workflow creation, but tedious task is to understand the syntax of JavaScript.

---

<div class="post-metadata">

**Author:** ![JhonU](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JhonU](https://community.dynatrace.com/u/JhonU)\
**Post date:** [June 16, 2024, 11:35pm UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/11 "2024-06-16T23:35:38Z")

</div>

Hi Omkar,&nbsp;I’m having a hard time understanding how to use JavaScript to get the information, could you help me by indicating which SDK you used since I’m looking to make a similar workflow and with the trigger data it would help me define my flow

---

<div class="post-metadata">

**Author:** ![Omkar\_B](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/omkar_b/32/7148_2.png) [@Omkar\_B](https://community.dynatrace.com/u/Omkar_B)\
**Post date:** [October 9, 2024, 2:20am UTC](https://community.dynatrace.com/t/build-workflow-to-send-sms-notification-for-problems-detected-after-business-hours/44552/12 "2024-10-09T02:20:02Z")

</div>

Hello&nbsp;[@JhonU](https://community.dynatrace.com/user/75688),  
If you’re still looking for it, here are the SDKs you can use.  
_@dynatrace-sdk/automation-utils_ :- to get details from previous tasks or trigger within execution.
