Rule Actions
Last updated
Last updated
In Nected, you can use rule actions to automate database operations based on specific conditions, enabling you to integrate with various database types, including MySQL, PostgreSQL, MongoDB, RedShift and so on along with REST API, Slack and Google Sheet. These operations can be performed using static queries or tokenized queries, providing flexibility and customization for your needs.
Triggering a database as a rule action in Nected involves a series of steps that are generally consistent across different types of databases like PostgreSQL, MySQL, MongoDB, Redshift, MS SQL Server and so on. Here's a simplified guide on how to trigger a database as a rule action, assuming that you have already completed the database integration, dataset creation, and rule creation steps:
Open the Rule Editor: You can tigger DB as rule action, in both SimpleRule as well as in DecisionTable. So, open the rule editor where you want to add the action.
Go to the Result section: After opening the rule editor, go to the result section. In the result section, there are two options, Then & Else. You can add actions for both of them.
Now, click on "+Add Action" button on either Then or Else part of the result section. Then a popup like this will be opened.
Then from the available options, choose any Database you want to use as actions(for example PostGres). Then click on that database option and will show the available databases like this:
Now, here either you can use the prebuid datasets, or you can create a new one.
If you want to choose the prebuild dataset, you can just click the dataset from the given list, and then a new modal will be opened like this:
Inside this editor modal, you can write queries to customize the action. You can also edit the dataset by clicking on the pen🖊️ icon.
Now if you want to create a new dataset, then you can do that from this same screen itself. You just need to click on dropdown button and then click on "+Create Connector".
This will redirect you directly to the connectors page where you can configure your connector. And after configuring, come back to this same editor, and here you can click the refresh ↻ button. Then you can see the connector in the dropdown list.
You can also create a new dataset directly inside the rule editor. If you don't want to go to the dataset editor, and want to create a new dataset connector, just click on "+Database_Name" button which will take you to the connectors page with the popup for configuring the specific database with proper credentials.
Next, configure the connection settings for your database, including host, port, username, password, and other required details.
After filling all the connector details click on the Test Connection
and check if the connector is working properly or not i.e. credentials are correct for your connectors. And after that publish the connection in staging first by clicking "Publish in Staging" and then repeat the same thing in production. Then finally publish it in production by clicking on Publish in Production
button.
Now once you've successfully established connection, come back to the rule editor and click the refresh ↻ button. Then you'll be able to see the new connector. Then simply click on the connector Then again the dataset editor will be opened. where you can now configure two types of operations.
Insert Operations: Specify the details of the new record you want to insert. This can be done by writing a SQL query for relational databases like PostgreSQL and MySQL, or a BSON query for MongoDB.
Update Operations: Define the criteria for the records that need to be updated and specify the new values. Again, this will be in the form of a SQL or BSON query, depending on the database.
Use Tokenized Queries (Optional): If you want the operation to be dynamic, based on the output data of the rule or other custom inputs, you can use tokenized queries. This involves using placeholders in your query that get replaced with actual values when the rule is executed.
Test the Rule Action: Before finalizing, it’s important to test the rule action to ensure it works as expected. This might involve checking if the database operation is carried out correctly when the rule is triggered.
Save and Activate the Rule: Once you are satisfied with the configuration, save the changes and ensure the rule is activated. This will enable the database operation to be automatically triggered whenever the conditions defined in the rule are met.
Monitor the Rule Execution: After activation, monitor the rule to ensure it is executing as expected. This might involve checking the database for changes or using any logging features provided by Nected.
By following these steps, you can effectively trigger a database operation as a rule action in Nected, automating data manipulation tasks based on specific conditions or events. This process enhances the interactivity and responsiveness of your application by integrating real-time database operations with rule-based logic.
If you have a REST API server, then you can use a REST API action in a rule to update your source database.
Note: All production rules must be run securely using an API, but you can choose to run a staging rule either using an API or directly on the Nected platform.
Follow this procedure to add REST API action in a rule:
Log into Nected with your Email ID and password.
Click Rules in the left navigation to open the Rules page.
Click + Create Rule button on the Rules page and select SimpleRule or DecisionTable. The rule configuration form opens. Define the condition and configuration for your rule.
Click Add Action and select the REST API connector for your database. The action REST API configuration form opens.
Provide the following information for the REST API action:
The following list describes the options on the REST API action window:
URL Path – The base URL for the REST API.
Method – The REST API method, which can be GET, POST, PUT, PATCH, or DELETE.
Headers – The authentication header retrieved from the REST API connector. You can add more headers using the Add Headers option. You can also add query parameters using the Add Query Parameters option.
Content Type – The type of the content that you want to update, which can be HTML, Text, JavaScript, JSON, XML, FORM, or FORM URL encoded.
The REST API data or body, which contains the information that you want to insert or update in your database.
Save – Save the REST API action information.
Trigger the rule using an API.
Triggering a Gsheet as a action in Nected involves a series of steps. Here's a simplified guide on how to trigger a Gsheet as a rule action, assuming that you have already completed the Gsheet integration and rule creation steps:
Select the Gsheet Operation: Nected provides you with 2 options i.e Add Single Row and Update Rows which includes inserting new records or updating existing records, respectively.
Configure the Operation Details:
For Add Operation: Select the spreadsheet by clicking on add sheet. Now choose a worksheet present from the selected spreadsheet . Addtionally define whether your first row in sheet serves as headers or not.
Test the Rule Action: Before finalizing, it’s important to test the rule action to ensure it works as expected. This might involve checking if the Gsheet operation is carried out correctly when the rule is triggered.
Save and Activate the Rule: Once you are satisfied with the configuration, save the changes and ensure the rule is activated. This will enable the Gsheet operation to be automatically triggered whenever the conditions defined in the rule are met.
Monitor the Rule Execution: After activation, monitor the rule to ensure it is executing as expected. This might involve checking the database Gsheet for changes or using any logging features provided by Nected.
Access the Rule Configuration: Navigate to the rule you have created within Nected. This is where you will specify the Gsheet operation you want to trigger as an action.
For Update Operation: Simply follow the steps we performed in add operation.