View Article

Create and Test a Logical Rule with One Condition

By Xelence Documentation posted 02-14-2022 15:11

  

Introduction

Logical rules are structured in a way that they define relationships, operations, or conditions that must be met for a particular conclusion or outcome to be valid. These rules are often used in reasoning, decision-making systems, and programming.

This example is a very simple logical rule just to demonstrate the interface. It determines the status of a record based on its verification.

After creating the rule, you can test it to confirm it works as expected.

Prerequisites

The entity must exist.

Quick Steps
1 Click the Create New Item icon, then select the Object Type
2 Select the Rule Type
3 Enter the rule details, then click OK
4 Write your rule logic in X#
5 Enter the logic for the rule components
6 Declare any variables
7 Save and compile the rule
8 Open the scenario, then open the test case
9 Enter the values and run the test
10 View the result diagram
11 Save the scenario

Detailed Steps

Step 1. Click the Create New Item icon, then select the Object Type.

The Create New Item icon is in the top left corner of Xelence’s landing page.
 
It begins the process of creating a new logical rule.


Step 2. Select the Rule Type.

The Object Type identifies the file the wizard will create. This example creates a logical rule.



Step 3. Enter the rule details, then click Ok.

The properties are:

  • Entity: The rule is based on the entity. The fields available to the rule will be based on this entity's attributes.
  • Name (ID): This is the rule's programmatic ID. This property is required. The ID must be unique, and it cannot start with numbers.
  • Access Modifier: Specifies the level of accessibility of the rule.
  • Return Type: This is the data type of the result you expect the rule to return (string, int, etc.).
  • Is Collection: This is available when the logical rule returns a result. If checked, the rule can return a collection.
  • Static: If checked, the rule will be available to call from anywhere. Otherwise, you will have to call it from an instance of its object. In a logical rule, the attributes of the entity can be directly used if it is not static.
  • Allow From Platform Api: If checked, the rule will be available from Platform API.
  • Trace: Making a rule traceable means you can view the path and result every time the code executes that rule.
  • Description: Optionally, you can enter a short description for your rule.
The Access Specifier options are:

Public: The rule is accessible from anywhere.
Private: The rule is accessible only from the current entity rules.
Protected: The rule is accessible only from this entity and any child entity.



Step 4. Write your rule logic in X#.

Xelence creates a new logical rule as a default empty page. You can build the rule by adding the code in X#. Alternatively, you can also build the rule flowchart by dragging and dropping components from the Toolbox in the Design mode. Refer Logical Rule Elements to get more details about Toolbox elements.



Step 5. Enter the logic for the rule components.

For each component, enter the description of what it does in the rule, then enter the expression. An expression is the actual logic that your application executes when it calls the rule.

Press Control key (ctrl) and / together on the keyboard to comment or uncomment any desired code block.
This rule starts with a switch. By default, a switch has two if block and one else block. You can add or remove as many blocks as you want, but we’ll keep it to just one.
Based on the results, the rule will take a defined action.


The rule returns a value based on the action it took.

In this rule, Productverificationind is not defined as a variable. Instead, it's an attribute of the Product entity.


Step 6. Declare any variables.

You must add any undefined components as variables by specifying the below properties:

  • Data Type: Type of data the variable uses (string, int, bool, etc.).
  • Variable Name: String you are adding as a variable.
  • Default: If the variable is local, you can assign it a default value.
You can also declare the variables before you enter the logic for the rule components.
In this example, lstrStatus is defined as a variable.

The rule is completely defined. We never defined "Y", but once lstrStatus is defined in the condition, we don't have to. Xelence knows it’s a string value for that variable as defined in variable declaration.
This is how the logical rule flowchart appears when opened in Design mode.


Step 7. Save and compile the rule.

When you are finished defining the rule, click the Save icon. 


You must compile the rule so it can be called. Click the Compile Rule icon to compile the rule.


The rule is configured. You may now call it elsewhere in your project, based on its accessibility and static settings.



Step 8. Open the scenario, then open the test case.

If you want to test the rule to confirm it returns the value you expect, click the Navigate to Scenario icon.



Step 9. Enter the values and run the test.

Select the default created test case. Enter the input value for the test. Optionally, you can enter the value you expect the rule to return. 

 Click the Run Test icon and select Current Rule to run the test step.

Xelence provides the following options for running the test:

Only Result: Displays only the result.
Current Rule: Displays the result and diagram for this rule.
Child Rule: Displays the execution of any child rule.



Step 10. View the result diagram.

The rule is executed successfully. Check the expected and actual value. The scenario passes if the expected value matches the actual value. If you want to trace the executed logic, click the View Test Result icon to open the result diagram.

The result diagram shows how the rule produced the return value. Click the Close icon to close the diagram.



Step 11. Save the scenario.

Click the Save icon to save the scenario.


What are the improvements over S3 Version 6?

This is an identical process. 


Related Articles

Logical Rule Elements

Use a Try Block in a Logical Rule and Test the Rule

Create and Test a Logical Rule with a Loop and Call to a Decision Table


This post is part of the Rules topic. Click here to open the Rules Overview.

#Xelence
#Rules

0 comments
183 views