SimpleRule

This documentation provides a technical guide for creating a simple rule within Nected, a platform designed for rule creation and management. Nected enables users to connect to various database systems, including PostgreSQL, MySQL, and MongoDB, and define rules to trigger specific actions based on data conditions.

This documentation is intended to assist users in creating simple rules without focusing on the specifics of any particular database system, as Nected is adaptable to different database technologies. It outlines the steps required to set up and configure a simple rule within the Nected platform, emphasizing the flexibility to integrate and work with a wide range of database options.

Creating a simple rule in Nected allows you to define specific conditions and actions based on your connected database's data. This section provides a step-by-step guide to creating a simple rule, emphasizing the flexibility to use various types of databases like PostgreSQL, MySQL, or MongoDB within the Nected platform.

Step 1: Create a New Rule

To create a new rule in Nected,

  1. Log into your Nected account and navigate to the Rules section available in the left sidebar.

  2. Click the + Create Rule button to open a popup with two configuration options:

    • Build your own

    • Start from template

  3. Choose Build your own to set up a Simple Rule from scratch:

    • Enter a Rule Name: Specify a name for your rule which clearly identifies its purpose.

    • Provide a Rule Description (Optional): Give a brief description of what the rule is intended to accomplish. This is helpful for future reference or for other users.

    • Select the Rule Type: Click on the Simple Rule option. A Simple Rule consists of if/else conditions processed all at once, typically used for customer segmentations, simple plan allocations, or referral bonus payouts.

This action will initiate the rule-creation process. However, before proceeding, it's important to choose the appropriate rule type for your specific use case.

Nected offers a total 3 rule types, each designed to address particular scenarios. You can read about each one of those here.

By choosing the right rule type, you can ensure that your decision-making process aligns with your specific use case. For more detailed information about each rule type and additional use cases they can address, please refer to the respective documentation links provided above.

Step 2: Define your Rule

In this step, you'll define essential rule information, including:

  1. Configure your rule by setting the necessary conditions and actions:

    • Define the if/else logic that will dictate how the rule behaves based on certain conditions.

    • Specify the actions to be taken when conditions are met or not met.

  2. Connect to a Data Source if needed (this is optional):

    • You can either use custom input parameters to pass data directly into the rule or connect to a database to retrieve data automatically, depending on your specific requirements.

  3. Rule Environment: The rule environment determines whether the rule will be executed in staging or production. Staging is a test environment where you can test your rules before deploying them to production. Production is the live environment where your rules will be executed for your customers. By default, all new rules are created in staging.

  4. To deploy a rule into the production environment it must be published. There is no need to switch to the production environment unless you wish to make changes to the rule settings. However, any changes to the rule settings will require republishing.

Rules can be executed in three different environments: a published rule in production, a published rule in staging, and a non-published rule in staging.

Read more on Triggering Rules via API.

Currently, there is no provision for testing non-published rules in the production environment.

Step 3: Add Input Attributes

Before configuring a rule in Nected, determine the data source that the rule will utilize. Nected offers versatility in data source definition:

  1. Direct Input Attributes: With Nected, you can designate custom attributes tailored to your rule. These act as dynamic values supplied alongside API parameters during rule execution. For example, for a discount rule, you might use parameters like "customer type" and "purchase amount." Such parameters offer on-the-fly adjustments when invoking the rule via an API.

  2. Fetch from your Database via DataSet: If you have an existing database, Nected lets you extract parameters directly from it through a dataset. By choosing a dataset, you can refer to its attributes within your rule conditions. For instance, for a rule assessing discounts from a customer's purchase history, you might use a sales dataset to access attributes such as "customer ID" or "total amount".

  3. Fetch from any internal/external API: Over Nected, you can integrate with any 3rd party API to fetch input attributes & data directly to be used in the Rule. For instance, you can fetch customer's KYC, credit history or purchase data with your vendor, and you want to use those data points as well as in your business logic.

  4. Combination of All: Merging custom input parameters with a dataset as well as API is the optimal method. It harnesses your dataset's structured data, let you combine 3rd party data but then also allows for specific parameter overrides when executing the rule. In the discount rule context, this means leveraging dataset information for general trends, while also accommodating unique discounts or promotions via custom parameters.

The right data source setup empowers your rules to span diverse scenarios, from utilizing historical data to making real-time adjustments based on distinct parameters.

Step 3.1: Add Custom Attributes

Should you need attributes absent from your dataset, or if you prefer a dataset-independent rule relying solely on custom attributes, you can define these as per your rule's needs.

  1. Just click on the "Add Input Attributes" Button and don't choose any dataset.

  2. Click on +Add Field and type in Key Name and choose Primitive Data Type from the dropdown. You won't need any Data Mapping as this is not from any dataset. You can choose the configuration if the field can be null, should be compared in case case-sensitive manner, and/or if it is optional. Eg - For the loan approval example, you might create attributes like light_intensity, soil_moisture, temperature and humidity.These attributes will be used in evaluating rule conditions.

  3. Click on Save

Nected further offers an efficient approach to adding input attributes from Datasets and API.

Step 4: Define Rule Condition

The rule condition section is where you define the criteria that must be met for the rule to fire. You can use a variety of operators and conditions to create complex rules.

Step 4.1: Configure Rule Properties

In this step, you can configure the following rule properties:

  • Custom Functions: This is a JavaScript editor where you can write a JavaScript formula that includes attribute-based tokens to define conditions in the rule. Custom functions provide flexibility in specifying complex logic.

  • Input Attributes: Input attributes are the local attributes created for use within this rule. These attributes can be used in conditions and actions within the rule.

  • System Attributes: System attributes are provided by the system and are related to time and other system-related information.

  • {Dataset}: If you've selected a dataset as the source, you can use attributes from the dataset to form conditions within the rule. This allows you to leverage the data in your dataset for decision-making.

Step 4.2: Define Conditions and Operators

Conditions are the criteria that determine when the rule should take action. You can create conditions using a variety of operators. Nected supports the following types of operators:

  • Common/Generic: Any, Exists, Does Not Exist, Is Null, Not Null

  • Numeric Ops: Between, Not Between, Equals, Not Equals, Greater than, Less than, Greater than or equals, Less than or equals, Is Even, Is Odd

For more detailed info about the operators, read this page Operators.

You can combine conditions using logical operators to form complex conditions. These logical operators include AND, OR, and NOT.

Step 4.2.1: Define the Values

Now after defining the operators for each properies, you need to define the values for them.

Values can mostly be constants or tokens of the same datatype as property.

Step 4.3: Condition and Group Creation

After defining conditions, you can organize them into groups. Groups help manage the logic flow of your rule. You can set the group type as "AND" or "OR," and conditions within a group are evaluated accordingly.

Step 5: Define Rule Results and Actions

Defining the results and actions of your rule is a critical aspect of its configuration. In Nected, both results and actions have distinct functionalities:

Adding Results:

When you add results, you specify the type of result you expect from the rule. Nected offers various result data types, including boolean, numeric, string, date, JSON, and custom JavaScript formulas. The choice of data type depends on the nature of the rule and the desired outcome.

The Rule Result works like below:

If{ 
      rule sets true
Then {Execute rule result for true}
}Else{ 
       Execute rule result for false
}

To add Rule Result, follow these steps:

  1. In the rule editor, you can find the Result just below of the If part.

  2. In the result section, there are two options, Then & Else. You can add results for both of them.

    • Inside Then, click +Add Result button, and a dropdown will appear. From there choose the type of result you want to return if the rule satisfies the true condition. Here are the types of data you can add: [Boolean, Numeric, String, Date, JSON, Custom JavaScript Formula]. The result will be denoted as key_name.

    • Similarly, if you want to return a rule result if the conditions are not met i.e. the rule returns false, then just go to the Else part, and similarly click +Add Result button. Then similarly you can choose and add the result you want to show.

  1. After configuring the Rule result, test it and check if they're working properly or not.

Adding Actions:

Adding actions allows you to specify what your rule should do when its conditions are met. Nected provides a wide array of action options, each tailored to serve different purposes. These actions can include sending notifications, updating a database, triggering external processes, and more. There are different types of action:

  • Database Operations: As a rule action, you can perform operations on a database, such as inserting, updating, or deleting records. This is valuable for keeping your data up-to-date.

  • Triggering REST API: Rules can trigger REST API calls, enabling interactions with external systems. This action can be customized to send specific payloads and parameters as needed.

  • Slack: You can add Slack as well as a rule action, to trigger some functions like sending notification or something else.

  • Google Sheet: Same as database, you can also trigger a google sheet, to do CRUD operations in the sheet or some other operations.

To add actions in rule, follow these steps:

  1. In the Result section, click on +Add Action button inside Then or Else part, according to when you want to trigger the Action.

  2. Then from the dropdown, select the specific type of action. And then configure your action. For more detailed guide follow the steps shown in Rule Action.

  3. After configuring the Rule action, test it and check if they're working properly or not.

The choice of data type and action depends on the objectives of your rule. Consider your use case and desired outcomes to select the most appropriate options. For detailed information on adding actions, you can refer to the rule actions.

Step 6: Testing

Nected allows you to test rules in a staging environment before deploying them to production. This helps to ensure that your rules are working as expected. To test a rule, click the Test button.

Testing scenarios

Nected supports a variety of testing scenarios, including:

  • Testing with different values for the input parameters.

  • Testing with null values for the input parameters.

  • Testing with optional input parameters.

Now, If a rule has nullable input parameters, you can test the rule with null values for those parameters. If a rule has optional input parameters, you can test the rule with and without those parameters.

Testing example

To test a rule with different values for the input parameters:

  1. Click the Test in Staging button.

  2. In the Test Rule dialog box, enter different values for the input parameters.

  3. Click the Test Now button.

  4. After the test is completed, it generates a JSON code as the output.

  5. If you see the success message (which you've given while adding data) in the code, that means your rule is ready to publish. If you see the failure message, that means your rule is not ready to publish.

Significance of testing

Testing is important to ensure that your rules are working as expected. By testing your rules in a staging environment before deploying them to production, you can prevent errors and ensure that your rules are not causing any unintended consequences.

Testing is mandatory to do on each edit before publishing to make sure that rule is behaving as expected and without errors.

Step 7: Publish the Rule

Once you are confident in the rule's functionality, publish it. This action makes the rule available for use within your Nected environment.

Step 8: Rule Access via API

Nected offers a powerful API that allows you to access and execute your rules programmatically. This means that you can integrate your rules with other systems and automate your decision-making process.

Example:

This example triggers the rule with the rule ID {652a0574438f52XXXXX} using curl.


curl -X "POST" "<https://nected-59.nected.io/nected/rule/652a0574438f52XXXXXXXXXX>"\\
-H 'Content-Type: application/json'\\
-d '{
"environment": "staging",
"isTest": false,
"params": {
"Soil": 0,
"humidity": 0,
"temperature": 0
}
}

You can see the exact steps to trigger rule via API here and utilizing Nected's API, you can seamlessly call your internal/external flows from within your rules based on its outcome, allowing you to make data-driven decisions effortlessly.

Rule Status: Managing Your Rules

In Nected, rules can go through three distinct statuses (Draft, Tested, Published/Live), each serving a specific purpose in the rule creation and deployment process.

These three statuses - Draft, Tested, and Live - provide a clear and organized framework for managing your rules within Nected, allowing you to seamlessly develop, test, and deploy rule-based decisions for your applications while maintaining a structured workflow.


As you continue to work with Nected, you may also explore additional features like the Decision Table and Rule Set. The Decision Table allows you to define and manage decision logic in a structured tabular format and is helpful when you want to set up different outcomes for different combos in excel like view. Rule Set provides a way to organize and execute multiple rules at once under a single umbrella.

Last updated