Process Data with Java and Write to a SQL Database with WayScript
Tags: startup, serverless, tutorial, wayscript
Published: 2020-11-04 15:50:25

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

Automate simple things can save you a lot of time in youy business.  
Today we’ll use WayScript to create a script to Process Data with Java and Write to a SQL Database.  
In this article, we’ll register in a SQL database all `create cards>` action in a Trello Board.

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

No prerequisites but some content you might find helpful:

*   [Working with Trello Trigger](https://docs.wayscript.com/library/triggers/trello-trigger)
*   [Working with Java](https://docs.wayscript.com/library/modules/java)
*   [Working with If/Else](https://docs.wayscript.com/library/logic/conditionals)
*   [Working with SQL](https://docs.wayscript.com/library/modules/sql)

Trigger
-------

As I said earlier, we want to register in the SQL database all `createCard`. WayScript provides a Trello Trigger we can use to follow up events we are going to specify, and use the data in the responses to make our script work.  
Add it as a new Trigger.

![Adding Trello Trigger](https://wayscript.com/blog_img/138/1.png)

Once it’s added, we can configure it.

![Configuration](https://wayscript.com/blog_img/138/2.png)

Once you’ve selected the board, be sure to have the following outputs selected too.

![Outputs](https://wayscript.com/blog_img/138/3.png)

Good, now we can move to the Java module.

Java Code
---------

We’ll use Java code to perform some actions on the data returned by the trigger. Our goal here is to return a boolean which will be True if the action on the board is `createCard`, then run the SQL script. Add it as a new Step.

![Java Module](https://wayscript.com/blog_img/138/4.png)

Once it’s added, click on Edit Code.

![Java Code](https://wayscript.com/blog_img/138/5.png)

*   Line 3: `WayScript.variables` is a dictionary containing all variables in the current script. We get the action type value that we convert to a String object.
*   Line 5: If the action type is `createCard` then, `isCreateCard` variable is true.
*   Line 9: We can also output data from the Java code, that will be used by other modules. We first specify the name of the variable we want in the script, followed by the variable of the Java Code.

We have a boolean value available in the script. We’ll use If modules to make comparisons and guess what, it’s very simple.

If Condition and SQL module
---------------------------

By using the If condition, we can make simple comparisons and decide on the behavior of our script.  
Add If module as a new step.

![Adding If module](https://wayscript.com/blog_img/138/6.png)

Once it’s done, we can set the conditions now.

![Condition](https://wayscript.com/blog_img/138/7.png)

Now, we have two branches. An If branch and an Else branch. If the condition is true, the script in the If branch will be executed, otherwise it will be the opposite.  
We’ll add the SQL module in the If branch then.  

![Adding SQL modules](https://wayscript.com/blog_img/138/8.png)

We can now write SQL queries.

![SQL code](https://wayscript.com/blog_img/138/9.png)

Great. We’ve nearly done. Be sure to have the Trello turned on and now your script is ready.

Conclusion
----------

Questions about this script or anything else? Join our [discord](https://discord.gg/VWbXSbj). We're always around to help. If you want to work the full script template, just find it [here](https://wayscript.com/user/mangabo_kolawole/SNR-QAQZ
        ).