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. You can add the below datatypes as input:

    1. String: To add string value click on the dropdown list and select "String" from the given option. Then add the test value like this:

    2. Numeric, Boolean: Similarly click on the dropdown button to select the respective datatype and then in the test value.

    3. Date & DateTime: To add Date or DateTime, you can select the datatype from the dropdown list and then you can just add the test value like this:

    4. JSON: To add JSON as input follow the guides here.

    5. List: To add LIST as input follow the guides here.

  4. Click on Save & Next

For String, Date & Date&Time attributes,

Step 3.2: Map with Data Source

To add a dataset as an input attribute you can follow the steps given below:

  1. After opening the Input Attribute window, you need to add a new blank custom property from the first tab. For example: "DB_Data".

  2. Then you need to click the second tab i.e. “Map with data source”. to map the new input attribute with your dataset.

  3. Inside that tab, you can see a dropdown list called “Select Dataset”. To map your attribute with the dataset you can either select a prebuild dataset from that dropdown list, or can create a new one.

    1. To create a new dataset for your rule, you just need to click on + Create Data Source Button.

    2. After Clicking this you will see lot of database connections options. Choose a database that you want to integrate it with the rule from the available dataset list i.e. MongoDB, MySql, PostgreSQL, Oracle, Redshift and so on.

    3. Now, after selecting the database for your rule it will be redirected to the connector page, where you need to fill all the connector 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.

    4. Now once you've successfully established connection, in order to fetch your data from database for the rule go to the Data sources page and then write query for the data you want to be fetched for your rule. Once you're done with writing the query, click on "Test Query" and test it thoroughly. After that publish the dataset and it is now ready to be fetched to your rule.

    5. Now, to use it over your rule, just come back to your rule's “Map with Data Source” tab and press the refresh icon just below of Select Dataset. And you’ll be able to see the new dataset that you’ve created.

    Now your dataset is available in the rule. To map click on +Add field and select the attribute(i.e. "DbData") that you’ve created in the “Input Attributes” tab and map it with the respective key from the dataset as the primary key.

Now you're ready to use the dataset values inside your rule condition as well as in the rule result.

Depending on what datatype you've selected for the custom attribute, you can only map those types of data of the dataset.

If your dataset contains multiple versions and you want to map with a specific version, then select that version from the dropdown list as shown below:

Step 3.3: Fetch From API

You can also add REST API as an input attribute. To do so, you can follow the steps given below:

  1. Then just click on the "+Add Input Attribute" and create a new input attribute, like "SampleAPI".

    1. Inside the modal, fill up all your rest api connector details and then test the connection by clicking on 'Test Connection" button.

    2. After testing the connection, click on "Publish in Staging" and then do the same thing in production. And then test the api connector in production as well and then publish it over production by clicking the "Publish in Production" button. And your API will now be ready for using inside the rule.

    3. Once done, just simply click the "Fetch Input Attribute via API" button to fetch the API data. And now you're ready to use the API data inside your rule condition as well as in rule result.

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.

    • NULL token: If you want to pass a NULL value in your rule condition, then you can select the NULL token inside the System Attribute.

  • {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 logical flow of your rule. You can set the group type as "AND" or "OR," and conditions within a group are evaluated accordingly.

To create a group follow these steps:

  1. Click on the 3 dot button at the right of any row, and you'll see the below options:

    1. Convert in a Group: This works on a single row. If you click on this button then it will convert that row into a group, like this:

    2. Leave a Group: This also works on a single row. If you click on this button then that row will leave that group and will go to the parent group, like this:

    3. Wrap: Wrap is similar to "Convert in Group" but for groups. To wrap into a group, you need to click on the 3 dot button at the right side of a group. And then click on "Wrap into Group" from the list. Then it will wrap that group into another group, like this:

    4. Unwrap: Unwrap is just the opposite of wrapping and it is similar to leaving a group. To unwrap a group from another group, you need to click on the 3 dot button at the right side of a group. And then click on "Unwrap Group" from the list. Then it will unwrap that group from the parent group, like this:

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.

      • NULL token: If you want to pass a NULL value in your rule result, then you can select the NULL token from the System Attribute.

    • 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

But, before making your rule live, make sure you change the version of the data source to live. Else you'll get an error like this:

To avoid this, change the version of the data source into a published version (it can be the latest live version or any other live version according to your requirements).

Finally, you can publish the rule. Now, while publishing, you will see two options on the screen:

  1. Publish to Production: You can publish the rule directly to production and use it over the API.

  2. Request for Review: You can assign an approver to validate your rule.

If you select the "Request for Review" button, it will follow the approval flow, which you can read about in detail here.

However, if you choose to publish the rule, there are a few things you should know about the publish flow.

The rule starts in a draft state. You can make any necessary edits to ensure it meets your requirements. Once you've done with the editing, you now can do two things:

  1. Submit it for Review: If you're working in a team, and there is a reviewer, then you can assign the reviewer and submit the rule in review. Then it will go into the review flow, which you can read from Approval Flow.

  2. Publish your SimpleRule: If you don't want to review your rule by an approver, then you can also directly publish your rule in production. Here is how you can do that:

    • When you are ready to publish, click the "Publish" button.

    • Title and Description: A prompt will appear asking for a title and description of the changes. This information helps maintain a clear version history.

    • Confirm Publishing: After providing the title and description, click the publish button to move the rule to production. The rule is now published and it will create a new published version that you can access from the Publish tab of the Version Control section. This version is live in the production environment.

Version Control:

If you edit a published SimpleRule and re-publish the updated rule, then it creates a new version of it. Now for any reason, if you want to check or roll back to a specific previous version, you can do that using the version Control tab. You can do this in two different ways:

  1. At the top bar, you can see the Environment tabs with numbers written alongside. These numbers show how many versions you have for that environment. Like in the image, you can see that I've 10 Published versions and 1 Draft version of that. Now, you can click on the respective environment to access the Version Control section like this:

  2. The second option is, you click on the just next icon of the settings icon, and it will open the Version Control section and from there you can access it.

To rollback to a previous version just click on the Rollback button on that version.

Dependency Mapping

So, as discussed in the previous section, if you're editing the ruleset and then publishing it, then it creates a new version. But if you're using this simplerule in any workflow or ruleset, and you want to check which version of this simplerule that workflow or ruleset is using, then you can do that using the "Dependency Map" section. To do this follow this:

  1. Click on the icon just below the Version Control icon, and it will open the Dependency Map section.

  2. Inside the Dependency Map section, you'll have two tabs:

    1. Using: In this tab, you can check which integration or data source, this simplerule is using.

    2. Used by: In this tab, you can check which ruleset or workflow is using this simplerule along with the version, as shown in the GIF.

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.

Step 9: Schedule

Scheduling is an independent step that allows you to schedule the corn job for your rule. If you’re testing the rule, i.e. if your rule is currently in staging, then you can click on test the scheduler by simply clicking the “Test Schedule” button. And it will run the cron job, for the first 10 rows of the database and return the result for them. After testing, you can also create a scheduler for your published rule from the “Create Schedule” button at the same place in the production environment. You can read more about it from the doc Scheduler.

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