DEV Community

Derrick Sherrill for WayScript

Posted on

Process Data with Java and Write to a SQL Database with WayScript

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:

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

Once it’s added, we can configure it.

Configuration

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

Outputs

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

Once it’s added, click on Edit Code.

Java Code

  • 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

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

Condition

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

We can now write SQL queries.

SQL code

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. We're always around to help. If you want to work the full script template, just find it here.

Top comments (0)