1. Home
  2. FlexRule Runtime (SDK)
  3. Commands
  4. Validation or Decision commands

Validation or Decision commands

Print Friendly, PDF & Email

◷ Reading Time: 7 minutes

Validation commands run in the validation engine that validates the input from users or other systems.

Validation

This command is the main container of the rule. It contains rule signature and one or multiple logic.

Summary

This is the main container of all logic for a validation rule.

Parameters

  1. name
    1. Description: Sets the name for a validation rule
    2. Mandatory: Yes
    3. Type: String
  2. enabled
    1. Description: Indicates whether or not the validation is enabled
    2. Mandatory: No
    3. Type: Boolean (true/false)
  3. useAgenda
    1. Description: When agenda is used, the consequences of Validation commands/Logic will be queued in activation to be fired later
    2. Mandatory: No
    3. Type: Boolean (true/false)

Internal Commands

Logic

The container for implementing the actual validation rule

Sample

<Validation name="Student Validation">
 
</Validation>

Logic

Validation may be divided into different parts. We call these Logic. This logic is Boolean in nature and will be run based on an input type. The input type will be represented by a type/class definition.

Summary

This is the main section implementing the actual reusable logic. Each validation or decision may have one or more Logic sections.

Logic uses a ‘name’ to be called or referenced. The name of logic must be unique throughout your validation or decision rules. However when logic is loaded within a RuleSet then you can specify the logic to be ‘scoped’. What that means is the name of logic must be unique only in the scope that is loaded. So you may have multiple logic with the same name but in different spaces.

Parameters

  1. name
    1. Description: Sets the name for the logic
    2. Mandatory: Yes
    3. Type: String
  2. variable
    1. Description: Local variable that is used as an input for the logic
    2. Mandatory: No
    3. Type: String (name of the local variable)
  3. scoped
    1. Description: Makes the logic name isolated in a scope that is loaded.
    2. Mandatory: No
    3. Type: Boolean (true/false)

Internal Commands

All validation logic rule commands except Logic, Validation, and Decision. Also RuleAPI:Procedural commands/Declarationcommand can define more input parameters in the logic.

Sample

<Logic name="IsNotNullOrEmpty" variable="$v">
   <Or negate="true">
      <Null value="$v" />
      <Empty value="$v" />
   </Or>
</Logic>

In the following logic, we call to other logic called basic validation.

<Logic name="person test">
   <And processAll="true">
      <Validate logic="basic validation" />
      <Regex pattern="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" value="Email" message="Email is not valid" tag="EmailError" />
   </And>
</Logic>

Then

This is an action set part of Logic and can be used only as part of a Logic.

Summary

The logic may have this command as part of an action when its conditions are met. Then the child’s action of this command will be executed. If there is no condition and the only element in the logic is the Then command, the action section will be executed.

Internal Commands

Child commands can be any of:

  • Var
  • Alias logic or method
  • Method Call
  • Procedure Call

Sample

Logic with conditions and Then section:

<Logic name="Check for females" priority="10">
  <And>
    <Check value='person.Sex == "Female"'/>
    <Validate logic="IllegalAge"/>
  </And>
  <Then>
    <Var name="result" value=""agenda: test2"" />
  </Then>
</Logic>

Logic with no conditions and Then section:

<Logic name="SetResultWithValue" variable="$a">
  <Then>
    <Var name="result" value="$a" />
  </Then>
</Logic>

Otherwise

This is an action set part of Logic and can be used only as part of a Logic.

Summary

A Logic may have this command as parts of action when it’s conditions are ‘NOT’ met. This is opposite to Then section.

Internal Commands

Child commands can be any of:

  • Var
  • Alias logic or method
  • Method Call
  • Procedure Call

Sample

Logic with conditions and Then section:

<Logic name="Check for females" priority="10">
  <And>
    <Check value='person.Sex == "Female"'/>
    <Validate logic="IllegalAge"/>
  </And>
  <Then>
    <Var name="result" value=""agenda: test2"" />
  </Then>
  <Otherwise>
    <Var name="result" value=""agenda: test3"" />
  </Otherwise>
</Logic>

Include

This command lets you include some external logic.

Summary

This command allows the logic to be external to the Validation. That means the logic can be shared between multiple Validation rules.

The format of the include source address depends on the type of ruleset you are using. Also, if your ruleset supports it you can use ‘*’ at the end of source uri which loads all of the models in that scope instead of one, by specifying the name.

Parameters

  1. name
    1. Description: Overrides the original name of logic
    2. Mandatory: No
    3. Type: String
  2. source
    1. Description: Address of the logic, it can be ruleset, http, ftp or file system address
    2. Mandatory: Yes
    3. Type: String

Sample

<Include source="ruleset://Common/Strings?parameter:name=NullOrEmpty" />
 
<!-- loads a logic and overrides its name to IsValid -->
<Include source="Common.NullOrEmpty.xml" name="IsValid"/>
 
<!-- this loads all the logic in scope: rules/treatments/Rows/5 --> 
<Include source="ruleset://rules/treatments/Rows/5/*" />

Boolean Operations

AND

Summary

These are aggregation commands used to perform a Boolean aggregation of some rules.

Parameters

Common validation command parameters as described

  1. processAll
    1. Description: Processes all of the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<And name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</And>

OR

Summary

These are aggregation commands used to perform a Boolean aggregation of some rules.

Parameters

  1. processAll
    1. Description: Enforced to process all of the collection even if logically can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<Or name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</Or>

XOR

Summary

These are aggregation commands used to do a Boolean aggregation of some rules.

Parameters

Common validation command parameters as described

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<Xor name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</Xor>

NOR

Summary

These are aggregation commands used to perform a Boolean aggregation of some rules.

Parameters

Common validation command parameters as described

  1. processAll
    1. Description: Enforced to process all the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<Nor name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</Nor>

NOT

Summary

These are aggregation commands used to perform a Boolean aggregation of some rules. The NOT command can have only one child.

Parameters

Common validation command parameters as described

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<Not name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</Not>

XNOR

Summary

These are aggregation commands used to perform a Boolean aggregation of some rules.

Parameters

Common validation command parameters as described

Internal Commands

Any validation rule commands except Logic and Validation

Sample

<Xnor name="1 or null" tag="1" message="all active items from E1100 through F0300 must equal [-]">
  <Null value="ItemValue" negate="true"/>
  <Check value="ItemValue.Value=="1"" />
</Xnor>

Conditions

When

If during different circumstances different checks need to behave differently, this command can be applied on the logic.

Summary

This command is similar to the When attribute in True and False. However, it enables more complex logic to be evaluated.

Sample

<False>
    <When>
        <And>
            <Check value="Age!=10"/>
            <Check value="IsMale==false"/>
        </And>
    </When>
</False>

True

Summary

These commands always return “true” or “false” unless the When attribute of the element changes its behavior.

Parameters

  1. when
    1. Description: The condition of the command: if the condition is evaluated as true, the result will be equal to the command; otherwise, it will be the opposite of the command (e.g., for the True command with a When the condition of false, the result is not True, meaning false.)
    2. Mandatory: No
    3. Type: String expression

Internal Commands

When

Sample

<True when="Age==null || Age.Length==0"/>

False

This check always returns false.

Summary

These commands always return “true” or “false” unless the ‘When’ attribute of the element changes its behavior.

Parameters

  1. when
    1. Description: The condition of the commands: if the condition is evaluated as true, the result will be equal to the command; otherwise, it will be the opposite of the command (e.g., for the True command with a ‘When condition of false, the result is not True, meaning false.)
    2. Mandatory: No
    3. Type: String expression

Internal Commands

When

Sample

<False when="Age.Length==0"/>

Checks

Empty

Summary

This command checks if the property is empty.

Parameters

Common validation command parameters as described

Sample

<Empty value="Name" />

Null

If null/nil check is required, this check can be used.

Summary

This command checks if the property is null.

Parameters

Common validation command parameters as described

Sample

Check if the Username or input object is null

<Or message="Please log in first!">
   <Null negate="true" value="input" />
   <Null negate="true" value="input.Username" />
</Or>

A Reusable logic to check the Null or Empty value of a passed string value

<Logic name="NullOrEmpty" variable="str">
  <Or>
    <Null value="str"/>
    <Empty value="str"/>
  </Or>
</Logic>

Contains

Check whether the logic contains a given value

Summary

Parameters

Internal Commands

Sample

Regex

This command preforms a regular expression check on a string value.

Summary

This command checks a pattern.

Parameters

  1. value
    1. Description: An expression to be evaluated as a Boolean result
    2. Mandatory: Yes
    3. Type: String expression
  2. pattern
    1. Description: The pattern of regex
    2. Mandatory: Yes
    3. Type: String

Sample

<Regex pattern="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" value="Email" message="Email is not valid" tag="EmailError" />

Check

This command preform checks on input values.

Summary

This command checks a condition.

Parameters

  1. value
    1. Description: An expression to be evaluated as a Boolean result
    2. Mandatory: Yes
    3. Type: String expression

Sample

<Check value="ItemValue.Value=="-""/>
or
<Check value="fin.FindById(this)"/>

Validate

Inside a validation, there may be several logics. This command can call a check from one logic to another.

Summary

An object is usually a composition of other different objects. When validation occurs in an object, the engine does not validate the entire graph of the object. If the engine reaches this command, it validates the provided property against the logic provided in the validation rule.

Parameters

  1. logic
    1. Description: Name of logic used for the validation of a property
    2. Mandatory: Yes
    3. Type: String expression (name of logic inside a validation rule)

Sample

<Validate name="person address" logic="address" value="Address" when="Address!=null"/>

The following example validates the call to the other logic to check Name and Family string.

<Validation name="SampleValidation">
 
  <Logic name="CheckFullName">
    <And>
      <Validate logic="CheckString" value="Name" message="Name cannot be null or empty" />
      <Validate logic="CheckString" value="Family" message="Family cannot be null or empty" />
    </And>
  </Logic>
 
  <Logic name="CheckString" variable="me">
    <Or negate="true">
      <Null value="me" />
      <Empty value="me" />
    </Or>
  </Logic>
 
</Validation>

Custom

Summary

Parameters

  1. Element Name: Alias element name
  2. Properties Collection: Collection of name/ values

Internal Commands

Sample

Collections

ForEach

This command performs the execution of rules for every element of a collection.

Summary

When a collection is being validated, this command can ensure rules are being executed against the collection elements.

Parameters

  1. childName
    1. Description: Name of the variable that can be referenced inside the command for each element
    2. Mandatory: Yes
    3. Type: String
  2. on
    1. Description: To provide an expression for an array to iterate through
    2. Mandatory: No
    3. Type: Boolean Expression
  3. processAll
    1. Description: Processes all of the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)
  4. until
    1. Description: Until the evaluation is false, continues to look
    2. Mandatory: No
    3. Type: Boolean Expression

Sample

<ForEach childName="c">
  <Null value="c.Line1" negate="true"/>
</ForEach>

UniqueConstraint

This command performs checks on a collection to ensure the uniqueness of elements.

Summary

When a collection is being validated, this command checks for the uniqueness of the element of the collection. It can validate the uniqueness of the elements by adding them as a set of constraints in the body of the command using Add element.

<Add property="nameOfProperty"/>

Parameters

Common validation command parameters as described

Sample

For an “Address” type with two properties called Line1 and line2:

<UniqueConstraint>
  <Add property="Line1"/>
  <Add property="Line2"/>
</UniqueConstraint>

Any

Condition validation for any of the items in a collection.

Summary

This commands allows validation to be applied on the item level of a collection. ‘Any’ would check for the existence of the first item in the collection. ‘All’ would enforce the condition to be met for all of the items in the collection.

Parameters

  1. source
    1. Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
    2. Mandatory: Yes
    3. Type: String
  2. name
    1. Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
    2. Mandatory: No
    3. Type: String
  3. on
    1. Description: It references the parameter or expression in a collection
    2. Mandatory: Yes
    3. Type: String (Parameter name or expression)
  4. processAll
    1. Description: Processes all of the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Sample

<Any on="Lines" value="$loop.Element.Product.RecordId>0" message="Some order lines has no product"/>

All

Validation condition for all of the items in a collection.

Summary

This command allows validation to be applied at the item level of a collection, as well as check for the existence of the first item in the collection. ‘All’ would enforce the condition that must be met for all of the items in the collection.

Parameters

  1. source
    1. Description: Address of the logic – it can be ruleset, HTTP, FTP or file system address
    2. Mandatory: Yes
    3. Type: String
  2. name
    1. Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
    2. Mandatory: No
    3. Type: String
  3. on
    1. Description: It references the parameter or expression in a collection
    2. Mandatory: Yes
    3. Type: String (Parameter name or expression)
  4. processAll
    1. Description: Processes all of the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Sample

<All on="Lines" value="$loop.Element.Product.RecordId gt 0" message="Some order lines has no product"/>

Count

Validation on numbers of items in a collection.

Summary

These commands allow the logic to be applied based on the number of items in a collection or based on the summation logic in a collection.

Parameters

  1. source
    1. Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
    2. Mandatory: Yes
    3. Type: String
  2. name
    1. Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
    2. Mandatory: No
    3. Type: String
  3. on
    1. Description: It references the parameter or expression in a collection
    2. Mandatory: Yes
    3. Type: String (Parameter name or expression)
  4. expect
    1. Description: Total value that is expected
    2. Mandatory: Yes if the value is not provided
    3. Type: Numeric
  5. by
    1. Description: This is the setting for the Sum command only and needs to be set to the Attribute of the line level of the collection
    2. Mandatory: Yes
    3. Type: String
  6. processAll
    1. Description: Processes all of the collection even if logically it can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Sample

<Count on="$lines"
           value='($loop.Passed==1)'
           expect="2"
           filter='$loop.Element.Product.Name=="Memory"'
           message="{0} Memory was supplied. Maximum of 2 and minimum of 1 is possible"
           tag="memory"
           by="RecordId"/>

Sum

Validation on a summation of a property of items in a collection

Summary

These commands allow the logic to be applied based on the number of items in a collection or based on the summation of logic in a collection.

Parameters

  1. source
    1. Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
    2. Mandatory: Yes
    3. Type: String
  2. name
    1. Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
    2. Mandatory: No
    3. Type: String
  3. on
    1. Description: It references the parameter or expression to a collection
    2. Mandatory: Yes
    3. Type: String (Parameter name or expression)
  4. expect
    1. Description: Total value that is expected
    2. Mandatory: Yes if the value is not provided
    3. Type: Numeric
  5. by
    1. Description: This is the setting for the Sum command only and needs to be set to the Attribute of the line level of the collection
    2. Mandatory: Yes
    3. Type: String
  6. processAll
    1. Description: Enforced to process all of the collection even if logically can be stopped
    2. Mandatory: No
    3. Type: Boolean (true/false)

Sample

<Count on="$lines"
           value='($loop.Passed==1)'
           expect="2"
           filter='$loop.Element.Product.Name=="Memory"'
           message="{0} Memory was supplied. Maximum of 2 and minimum of 1 is possible"
           tag="memory"
           by="RecordId"/>

Default Actions

Var

This command will manage a defined parameter’s value. It can access the value and manipulate it. The value can be in any type and the command is able to read and write the value or properties of a value.

Summary

This command can be used to evaluate all expressions (i.e., normal, monadic, functions, etc.). Or, when the name attribute is specified, it updates the parameter. For example, it assigns a value to a variable, which can be a simple primitive value such as an integer or a double type, or a computational formula, and (b) accepts nested addressing as the variable name in order to access other scope variables.

When the name is not defined, it evaluates the entire expression that is defined in the value attribute. In this case, all the variables that are used in the expression must refer to defined parameters in the declaration section.

Parameters

  1. name
    1. Description: Name of the target variable affected by the calculation or assignment, or alternatively the nested address. This name must be defined in the declaration section of the model.
    2. Mandatory: No
    3. Type: String
  2. value
    1. Description: Contains the value or formula
    2. Mandatory: Yes (either value of ref is required)
    3. Type: String
  3. path
    1. Description: Enables a set value, not insider properties, on the target object by referencing the properties using a dot or an element of an array using brackets, such as [3] and [index] (index can be an integer variable defined in running context). When the variable you are referencing in name has got some inner properties and you want to target them to update, you can use this setting.
    2. Mandatory: No
    3. Type: String (referencing object property of array index)
  4. reference
    1. Description: Reference to the variable name
    2. Mandatory: Yes (either value of ref is required)
    3. Type: String

Internal Commands

Extension

This command defines an extension point in the variable value assignment/calculation process. It must supply two parameters – assembly and handler – and the extension type must implement an interface named IExecutionExtension.

Value

Sometimes, the value cannot be assigned with a set attribute of value to the Var command, but it can be assigned with the Value command as an internal element.

Sample

Change an variable named ‘age’ value to ’10’

<Var name="age" value="10">

Or

Change a property ‘FirstName’ of variable named ‘person’ value to ‘Joe’

<Var name="person" path="FirstName" value='"Joe"'>

Or

<Var name="Menswear">
   <Value>
     <![CDATA[
      This is a multi line text!
      Line 1
      Line 2
      Line 3
   ]]>
   </Value>
</Var>

Or

<Var name="StarTotalPrice" value="(StarQty * StarPrice) - ((StarQty * StarPrice) * StarQtyDiscount)" />

Or

In this case item must be defined in the declaration section of the model.

<Var value="item.StarTotalPrice = (StarQty * StarPrice) - ((StarQty * StarPrice) * StarQtyDiscount)" />

Or

<Var name="StatementResult" source="xmlData" value="StatementAmount" process="true">
   <!-- 
     We want to handle the assignment inside our assembly
     if in this case it is an xpath value.
   -->
   <Extension assembly="Sample.Advert.dll" handler="Sample.XPathValue"/>
</Var>

CallREST

Calls out to any REST API and returns the results.

Summary

Allows collecting data through a REST API.

Parameters

  1. Address: Url and the Url Parameters for the REST API endpoint
    1. Url: The target URL of the REST endpoint
    2. Parameters: Url parameters of the REST API call. Use { and } to bindthem to execution context Parameters.
  2. Selector: Selector of the REST API
  3. Headers: Header of the REST API
  4. Verb: Method to call the API (GET, POST, PUT, DELETE, PATCH, HEAD, CONNECT, OPTIONS, TRACE)
  5. Body: Expression as the Body payload to be sent by the REST call
  6. Authorization: Credential of the API
    1. Username: User name for service authorization header
    2. Password: Password for service authorization header
    3. Token: Access token of client to communicate to a service end point
  7. Results
    1. Multiple: True selects multiple results (multiple objects)
    2. Result Path: Property’s path expression
    3. Copy Value To: Refers to a Variable parameter that the call result will be stored into it

Internal Commands

Sample

CallMethod

When there are objects defined inside a rule, this command can make a call to the object methods.

Summary

This command enables you to make a method call on a CLR object. You can pass the object reference to the procedure from the application or create the object using object creation commands. Either way, this command enables a method call on the instantiated object.

The method parameter can be passed directly as part of the method signature or in a more controlled form through the Param command.

Parameters

  1. method
    1. Description: Name of the method of the object, which also includes the object reference
    2. Format
      1. objectReference.MethodName(param1, param2, param3)
      2. objectReference.MethodName (In this format, Param commands are mandatory.)
    3. Mandatory: Yes
    4. Type: A string in the given format
  2. return
    1. Description: A variable in which the method result is stored
    2. Mandatory: No
    3. Type: String (name of the variable)

Internal Commands

Param

This command passes a value to the method for referencing.

Sample

<CallMethod method="xmlData.Write(34.3)" />
 
Or
 
<CallMethod method="xmlData.DisplayAdvert">
     <Param ref="Menswear"/>
</CallMethod>

CallProc

If your application logic is complex and requires multiple Procedural rules, this command can call an externally defined rule and return the result to the running execution context.

Summary

In a procedural engine, multiple procedures can be interlinked. This means that a procedural rule can execute another rule; thus, the context of the parent rule can be shared, and the result can be copied back to the root context. Different scenarios can be managed in several ways.

Parameters

  1. contextMode
    1. Description: Sets the context for the called procedure
    2. Mandatory: Yes
    3. Types
      1. New: Creates a new context and uses such context for execution; in this case, the variable of the new context must be registered by the Param command
      2. Shared: Uses the current context for execution and the new procedure after finishing the procedure execution; the current execution variable context (of only out-variables) is copied to the original one
  2. resultCopyMode
    1. Description: This attribute is set when the target procedure has variables that need to be accessed via the root executing procedure.
    2. Mandatory: Yes
    3. Types
      1. None: Does not copy
      2. AddOut: Copies out-variables
      3. AddIn: Copies in-variables
      4. AddBoth: Copies both in- and out-variables
  3. return
    1. Description: Sets a value of a parameter as a return value of the operation/call
    2. Mandatory: No
    3. Types: String (name of a parameter)

Internal Commands

Param

This command passes a value to the procedure and registers new variables in a new context if required.

ProcSource

This command provides the rule with a source to be loaded and executed. It can be a relative or absolute file path or a RuleSet address. If it is a relative file path, the location is initiated from your application’s execution folder. If it is a RuleSet address, it should be a valid address, and the engine should be initialized using RuleSet overload.

Sample

<CallProc contextMode="Shared" resultCopyMode="AddOut" >
   <ProcSource uri="Rules/Ver2/CalculatePriceSubTotal.xml" />
   <!-- 
         When we use contextMode="New" we need to pass the
         required parameter for the target procedure, otherwise
         all of the variables are shared in the main procedure and do
         not need to pass <Param .... />
 
   <Param name="StarQty" ref="StarQty"/>
   <Param name="GoldQty" ref="GoldQty"/>
   <Param name="SilverQty" ref="SilverQty"/>
 
  -->
   <Param name="StarQtyDiscount" ref="StarQtyDiscount"/>
   <Param name="GoldQtyDiscount" ref="GoldQtyDiscount"/>
   <Param name="SilverQtyDiscount" ref="SilverQtyDiscount"/>
 
</CallProc>

Updated on July 31, 2019

Was this article helpful?

Related Articles