Rule Actions

Database Operations As Rule Action

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, and RedShift. These operations can be performed using static queries or tokenized queries, providing flexibility and customization for your needs.

Create Connectors (One-Time Setup)

Before performing database operations as rule actions, you need to create connectors for the respective database types. Follow these steps to create connectors for each type of database:

1. Create a Connector

  • Click on the "Connectors" tab in the Nected interface.

  • Select the "Create Connector" option.

  • Choose the appropriate database type (e.g., MySQL, PostgreSQL, MongoDB, or RedShift).

  • Configure the connection settings for your database, including host, port, username, password, and other required details.

2. Save and Test

  • Once you've configured the connection settings, save the connector.

  • To ensure the connection is working correctly, click the "Test Connection" option. This step is crucial to verify that Nected can establish a connection to your database.

Triggering Dataset as Rule Action:

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, and Redshift. 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:

  1. Access the Rule Configuration: Navigate to the rule you have created within Nected. This is where you will specify the database operation you want to trigger as an action.

  2. Select the Database Operation: Depending on the type of database you are using (PostgreSQL, MySQL, MongoDB, Redshift etc.), you will have different operations available. These can include inserting new records, updating existing records and so on.

  3. Configure the Operation Details:

    • For 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.

    • For 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Database: MySQL

1. Inserting New Financial Transactions

1.1 Static Query

To insert new financial transactions into a MySQL database as a rule action, you can use the INSERT INTO statement with static values. For example, if you want to log a new deposit:

Action:

  1. Select the "Insert" action for your rule.

  2. In the "SQL Query" box, enter the following query:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('2023-10-21', '09:30:00', 106, 'Deposit', 1500.00, 'USD', 'Client Payment', 'Completed');

1.2 Using Tokenized Attributes

You can make the query dynamic and utilize data from rule attributes by using tokenized queries. For instance, to insert a new transaction with attributes from the rule's output:

Action:

  1. Select the "Insert" action for your rule.

  2. In the "SQL Query" box, enter the following query:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('{{.outputData.transaction_date}}', '{{.outputData.transaction_time}}', {{.outputData.account_id}}, '{{.outputData.transaction_type}}', {{.outputData.amount}}, '{{.outputData.currency_code}}', '{{.outputData.description}}', 'Completed');

2. Updating Transaction Status

2.1 Static Query

To modify the status of specific transactions in a MySQL database, you can use the UPDATE statement with static values. For example, if a rule action is set to change the status of a transaction:

UPDATE financial_transactions
SET status = 'Completed'
WHERE transaction_id = 21;

2.2 Using Tokenized Attributes

For a more dynamic update of the status based on rule attributes, you can use tokenized queries. If you want to update the status of a transaction based on the rule's output:

UPDATE financial_transactions
SET status = '{{.outputData.new_status}}'
WHERE transaction_id = {{.outputData.transaction_id}};

These steps provide you with guidance on how to perform database operations as rule actions in a MySQL database within Nected, using both static and tokenized queries.

Database: PostgreSQL

1. Inserting New Financial Transactions

1.1 Static Query

To insert new financial transactions into a PostgreSQL database as a rule action, you can use the INSERT INTO statement with static values. For example, if you want to log a new deposit:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('2023-10-21', '09:30:00', 106, 'Deposit', 1500.00, 'USD', 'Client Payment', 'Completed');

1.2 Using Tokenized Attributes

To make the query dynamic and utilize data from the rule's attributes, you can use tokenized queries. For instance, to insert a new transaction with attributes from the rule's output:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('{{.outputData.transaction_date}}', '{{.outputData.transaction_time}}', {{.outputData.account_id}}, '{{.outputData.transaction_type}}', {{.outputData.amount}}, '{{.outputData.currency_code}}', '{{.outputData.description}}', 'Completed');

2. Updating Transaction Status

2.1 Static Query

You can use the UPDATE statement with static values as a rule action to modify the status of specific transactions. For instance, if a rule action is set to change the status of a transaction:

UPDATE financial_transactions
SET status = 'Completed'
WHERE transaction_id = 21;

2.2 Using Tokenized Attributes

To make the status update dynamic and utilize data from the rule's attributes, you can use tokenized queries. For example, if you want to update the status of a transaction based on the rule's output:

UPDATE financial_transactions
SET status = '{{.outputData.new_status}}'
WHERE transaction_id = {{.outputData.transaction_id}};

Database: MongoDB

1. Inserting New Financial Transactions

1.1 Static Query

To insert new financial transactions into a MongoDB collection as a rule action, you can use the insert operation with static values. For example, if you want to log a new deposit:

db.financial_transactions.insert({
  transaction_date: '2023-10-21',
  transaction_time: '09:30:00',
  account_id: 106,
  transaction_type: 'Deposit',
  amount: 1500.00,
  currency_code: 'USD',
  description: 'Client Payment',
  status: 'Completed'
});

1.2 Using Tokenized Attributes

To insert data dynamically from rule attributes, you can use tokenized queries. For instance, to insert a new transaction with attributes from the rule's output:

db.financial_transactions.insert({
  transaction_date: '{{.outputData.transaction_date}}',
  transaction_time: '{{.outputData.transaction_time

}}',
  account_id: {{.outputData.account_id}},
  transaction_type: '{{.outputData.transaction_type}}',
  amount: {{.outputData.amount}},
  currency_code: '{{.outputData.currency_code}}',
  description: '{{.outputData.description}}',
  status: 'Completed'
});

2. Updating Transaction Status

2.1 Static Query

To update the status of specific transactions in a MongoDB collection, you can use the update operation with static values. For instance, if a rule action is set to change the status of a transaction:

db.financial_transactions.update(
  { transaction_id: 21 },
  { $set: { status: 'Completed' } }
);

2.2 Using Tokenized Attributes

To update the status of a transaction based on rule attributes, you can use tokenized queries. For example, if you want to update the status of a transaction based on the rule's output:

db.financial_transactions.update(
  { transaction_id: {{.outputData.transaction_id}} },
  { $set: { status: '{{.outputData.new_status}}' } }
);

Database: RedShift

1. Inserting New Financial Transactions

1.1 Static Query

To insert new financial transactions into an Amazon RedShift database as a rule action, you can use the INSERT INTO statement with static values. For example, if you want to log a new deposit:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('2023-10-21', '09:30:00', 106, 'Deposit', 1500.00, 'USD', 'Client Payment', 'Completed');

1.2 Using Tokenized Attributes

To make the query dynamic and utilize data from the rule's attributes, you can use tokenized queries. For instance, to insert a new transaction with attributes from the rule's output:

INSERT INTO financial_transactions (transaction_date, transaction_time, account_id, transaction_type, amount, currency_code, description, status)
VALUES ('{{.outputData.transaction_date}}', '{{.outputData.transaction_time}}', {{.outputData.account_id}}, '{{.outputData.transaction_type}}', {{.outputData.amount}}, '{{.outputData.currency_code}}', '{{.outputData.description}}', 'Completed');

2. Updating Transaction Status

2.1 Static Query

You can use the UPDATE statement with static values as a rule action to modify the status of specific transactions in an Amazon RedShift database. For instance, if a rule action is set to change the status of a transaction:

UPDATE financial_transactions
SET status = 'Completed'
WHERE transaction_id = 21;

2.2 Using Tokenized Attributes

To make the status update dynamic and utilize data from the rule's attributes, you can use tokenized queries. For example, if you want to update the status of a transaction based on the rule's output:

UPDATE financial_transactions
SET status = '{{.outputData.new_status}}'
WHERE transaction_id = {{.outputData.transaction_id}};

These examples demonstrate how to perform database operations as rule actions in various database types, including MySQL, PostgreSQL, MongoDB, and RedShift, using both static and tokenized queries. This flexibility allows you to tailor your database operations to your specific integration and automation needs.

Triggering REST API as Rule Action

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:

  1. Log into Nected with your Email ID and password.

  2. Click Rules in the left navigation to open the Rules page.

  3. 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.

  4. Click Add Action and select the REST API connector for your database. The action REST API configuration form opens.

  5. Provide the following information for the REST API action:

    The following list describes the options on the REST API action window:

    1. URL Path – The base URL for the REST API.

    2. Method – The REST API method, which can be GET, POST, PUT, PATCH, or DELETE.

    3. 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.

    4. 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.

    5. The REST API data or body, which contains the information that you want to insert or update in your database.

    6. Save – Save the REST API action information.

  6. Trigger the rule using an API.

Trigger Google sheet as Action

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:

  1. 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.

  2. Configure the Operation Details:

    1. 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.

  3. 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.

  4. 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.

  5. 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.

Last updated