Creating a Rule
Rules are used to manipulate and retrieve data within an AppBase Solution. Rules can be called by users, events, other rules, scheduled tasks, or from an outside system through a REST call.
You can create a business rule in several ways:
- Manually create a business rule using the AppBase system.
- Generate a rule automatically using the AppBase rule generator. AppBase contains many pre-defined business rule templates that may be selected when creating a rule via a rule generator.
- Generate a rule automatically using the AppBase rule generator and modify it to suit your needs.
- Create a composite rule using the composite rule builder – this will involve linking several rules together and will be implemented as C# code.
Manually Rule Creation
This procedure explains how to create a business rule for a business object manually. You can modify the rule later if you choose.
- Navigate to Business Rules > Rules (1) to open the rules tab.
- Click on the New Rule (2) button to open the New Rule tab.
- In the Rule Name field, enter a unique rule name
- Select a Tag that the rule can be categorized against
In the Rule Usage dropdown list, select the rule function. To check the lists of available rule usages and their meanings, go to Rules Usage.
- Enter a description for the rule in the Description field. This is for internal use only but is an important field to complete to ensure that other developers are aware of the purpose of the rule at a high level.
In the API Permanent ID enter a unique name to create an API permanent ID for this attribute. The system will automatically complete this field for you by default, but you can override if required (ensuring no whitespaces or special characters are included)
In the Rule Type dropdown list, select a rule type to assign to the selected rule (i.e., the language that the rule will be written in). The following table lists the possible Rule Types and their meanings.
- Specify the Local Path where the rule source code will be saved. Click the magnifier icon and select the Solution Resources (1) select the folder (2) and click the Select path button to save the path. In our example, we have selected the folder Rules/SMPL.
- Depending on how the rule will be used, select the Rule must be deployed to option. Options are None, Procedure/Function, Trigger.
- Identify if the call of the rule will be case sensitive or not, checking the Is Case Sensitive checkbox.
- To specify that the Eval Body is to be used, select Is Eval Body checkbox.
- To specify that the rule is to be public, select the Is Public checkbox.
- To specify how the response will be treated, select the Encoder. Use Default or None.
Api Call Timeout is an optional property, and it is not necessary to change this value for most of the Solution Rules (for rules that are EXPECTED to run for a long time - like data migration rules, change the property accordingly).
- The Data Quota Size constraint is compared to data units consumed by the rule. A negative value disables constraint - the operations will continue normally even if they exceed the configured on the Rule Modify Data Quota Size value. A zero (0) value is an accepted value, but using a zero value will terminate any supported rule after it reads data for rules that do not provide a greater Data Quota Size value on the Rule Modify page.
- The Code Body field is the location for the code of the rule (SQL or C#). Paste the code here or type it directly.
- When you have finished defining the new rule, click Save at the top of the form. To define more rules, click Save and New.
Using Rule Generator
- The rule generator window will appear, which is the starting point for building your rule.
- Select the Attributes (Fields). In our example, CaseId and DueDate. Double-click the label to modify the Label if needed.
- In the Search Criteria tab, and select the Attribute(s) to search for. In our example, CreatedDate. Check the code, which added a WHERE clause and a parameter.
- In the General tab, assign a Name, and a Description of the rule.
- In the Parameters tab, verify the name of the parameters. If needed, click the pencil icon to modify the parameter type and default value.
- In the Schema Columns tab, verify the output fields. Click the pencil icon to modify the Type if needed.
- Click Finish to save the new rule.
Rule Type Description
Rule Type | Description |
---|---|
CSharp | The rule is written using the C# language within the Microsoft .NET Framework. |
SQL | This rule type operates on database tables and fields using exact names specified by SQL code. Tied to the database and database schema. Returns an entire set of records for a specified business entity |
SQL Paginated | A rule that returns a paginated set of records |
SQL Scalar | A rule that returns a single value |
SQL Non Query | A rule that executes SQL that creates, updates, or deletes records within the database |
XML | Usually for dictionaries |
Spring.NET | Spring.NET is an open-source application framework that promotes well-established patterns in building enterprise .NET applications. One of the features provided by Spring.NET is the ability to set up business rules, create relevant configurations, and execute those rules by means of a framework. |
Decision | A decision rule type is used by various solution components when a decision has to be made. For example, those rules may be used for workflows to determine the next Activity and participant in a workflow process. In the workflow, an Activity might be linked to five subsequent Activities. The decision rule determines through which Transition and to which Activity the work item will be sent and to which participant it will be assigned. This sending decision depends on the properties of the work item and/or related business objects. |
Extension | Creates a rule type based on a DLL extension that was previously registered. This rule type allows you to select from a list of DLL extensions and then select a specific class and method that should be called. This rule type provides the ability to develop and invoke the functionality of any complexity or use functionality provided by third-party libraries. |
Composite | Configures a composite wizard to create a composite rule wherein multiple rules are linked. The final rule is generated in C# |