Automatically Send Text Messages when a Database Conditional is True
Tags: wayscript, productivity, tutorial, cloud
Published: 2020-06-19 11:03:04

Introduction
------------

Setting up automatic notifications can help you make better decisions, quicker. It can often be hard to create these automations if the decisions that need to be made are complex. For example, if we need to process datasets or filter selections before making decisions, these automations usually are more difficult to make. With WayScript, we can create these automations in minutes, while still having full control of our script.

Prerequisites
-------------

No prerequisites but some content you might find helpful:

*   [Working with our SQL Module](https://docs.wayscript.com/library/modules/sql)
*   [Working with our Time Triggers](https://docs.wayscript.com/library/triggers/time-trigger)
*   [Working with our Text Messages](https://docs.wayscript.com/library/modules/text-message)

Automating an Action at Intervals
---------------------------------

The automation part of this tutorial will occur with the time trigger. This will be the interval at which we want to check our database for the conditionals. On WayScript, we're able to easily automate complex interactions on a schedule. Whether you need to run a script by the day, hour, or minute, you can easily do this in our editor. To start programming on WayScript, sign up on the [home](https://www.wayscript.com) page, or login to your account. We can create scripts, by clicking on the "+ New Script" at the top of the webpage. These scripts are what will house our automations.  
We're able to automate anything on a schedule using [time triggers](https://docs.wayscript.com/library/triggers/time-trigger). We can pull a time trigger into our workflow and configure the settings:

![](https://cdn.wayscript.com/blog_img/76/1.png)

  

![](https://cdn.wayscript.com/blog_img/76/2.png)

  
In this example, we'll use this time trigger to do periodic checks on our database, looking for the conditional change to send a text message alert for.

Querying our Database
---------------------

To Query items in our database, we first need to drag in a [SQL](https://docs.wayscript.com/library/modules/sql) module into our workflow.  

![](https://cdn.wayscript.com/blog_img/76/3.png)

  
Once we connect our database, this will give us access to a full editor that we can write SQL code into. If you get stuck while trying to set up your database, feel free to reference this [Youtube tutorial](https://youtu.be/hR_grpalY-8). Let's write something like:
<pre>
SELECT SUM(quantity) FROM order_summary WHERE product='A';
</pre>
  
Once with have this information, we can compare it using conditionals in our workflow:

![](https://cdn.wayscript.com/blog_img/76/4.png)

  
The above image depicts an if statement which compares the value we pull from the database directly, to the value in the last run. We can store these values between runes using the variable storage module on WayScript. If the values are different, then a notification of your choice can be sent using the true branch of the if statement. In this example, we're using the built in text message module.

#### Questions, Concerns?

If there's any questions feel free to message us on discord. We're happy to help! If you want to see this full script template, you can find it [here](https://wayscript.com/user/derricks/qTc-gQR5)