◷ 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.
This is the main container of all logic for a validation rule.
- name
- Description: Sets the name for a validation rule
- Mandatory: Yes
- Type: String
- enabled
- Description: Indicates whether or not the validation is enabled
- Mandatory: No
- Type: Boolean (true/false)
- useAgenda
- Description: When agenda is used, the consequences of Validation commands/Logic will be queued in activation to be fired later
- Mandatory: No
- Type: Boolean (true/false)
Logic
The container for implementing the actual validation rule
<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.
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.
- name
- Description: Sets the name for the logic
- Mandatory: Yes
- Type: String
- variable
- Description: Local variable that is used as an input for the logic
- Mandatory: No
- Type: String (name of the local variable)
- scoped
- Description: Makes the logic name isolated in a scope that is loaded.
- Mandatory: No
- Type: Boolean (true/false)
All validation logic rule commands except Logic, Validation, and Decision. Also RuleAPI:Procedural commands/Declarationcommand can define more input parameters in the logic.
<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.
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.
Child commands can be any of:
- Var
- Alias logic or method
- Method Call
- Procedure Call
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.
A Logic may have this command as parts of action when it’s conditions are ‘NOT’ met. This is opposite to Then section.
Child commands can be any of:
- Var
- Alias logic or method
- Method Call
- Procedure Call
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.
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.
- name
- Description: Overrides the original name of logic
- Mandatory: No
- Type: String
- source
- Description: Address of the logic, it can be ruleset, http, ftp or file system address
- Mandatory: Yes
- Type: String
<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
These are aggregation commands used to perform a Boolean aggregation of some rules.
Common validation command parameters as described
- processAll
- Description: Processes all of the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
Any validation rule commands except Logic and Validation
<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
These are aggregation commands used to perform a Boolean aggregation of some rules.
- processAll
- Description: Enforced to process all of the collection even if logically can be stopped
- Mandatory: No
- Type: Boolean (true/false)
Any validation rule commands except Logic and Validation
<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
These are aggregation commands used to do a Boolean aggregation of some rules.
Common validation command parameters as described
Any validation rule commands except Logic and Validation
<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
These are aggregation commands used to perform a Boolean aggregation of some rules.
Common validation command parameters as described
- processAll
- Description: Enforced to process all the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
Any validation rule commands except Logic and Validation
<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
These are aggregation commands used to perform a Boolean aggregation of some rules. The NOT command can have only one child.
Common validation command parameters as described
Any validation rule commands except Logic and Validation
<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
These are aggregation commands used to perform a Boolean aggregation of some rules.
Common validation command parameters as described
Any validation rule commands except Logic and Validation
<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.
This command is similar to the When attribute in True and False. However, it enables more complex logic to be evaluated.
<False>
<When>
<And>
<Check value="Age!=10"/>
<Check value="IsMale==false"/>
</And>
</When>
</False>
True
These commands always return “true” or “false” unless the When attribute of the element changes its behavior.
- when
- 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.)
- Mandatory: No
- Type: String expression
When
<True when="Age==null || Age.Length==0"/>
False
This check always returns false.
These commands always return “true” or “false” unless the ‘When’ attribute of the element changes its behavior.
- when
- 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.)
- Mandatory: No
- Type: String expression
When
<False when="Age.Length==0"/>
Checks
Empty
This command checks if the property is empty.
Common validation command parameters as described
<Empty value="Name" />
Null
If null/nil check is required, this check can be used.
This command checks if the property is null.
Common validation command parameters as described
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
Regex
This command preforms a regular expression check on a string value.
This command checks a pattern.
- value
- Description: An expression to be evaluated as a Boolean result
- Mandatory: Yes
- Type: String expression
- pattern
- Description: The pattern of regex
- Mandatory: Yes
- Type: String
<Regex pattern="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" value="Email" message="Email is not valid" tag="EmailError" />
Check
This command preform checks on input values.
This command checks a condition.
- value
- Description: An expression to be evaluated as a Boolean result
- Mandatory: Yes
- Type: String expression
<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.
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.
- logic
- Description: Name of logic used for the validation of a property
- Mandatory: Yes
- Type: String expression (name of logic inside a validation rule)
<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
- Element Name: Alias element name
- Properties Collection: Collection of name/ values
Collections
ForEach
This command performs the execution of rules for every element of a collection.
When a collection is being validated, this command can ensure rules are being executed against the collection elements.
- childName
- Description: Name of the variable that can be referenced inside the command for each element
- Mandatory: Yes
- Type: String
- on
- Description: To provide an expression for an array to iterate through
- Mandatory: No
- Type: Boolean Expression
- processAll
- Description: Processes all of the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
- until
- Description: Until the evaluation is false, continues to look
- Mandatory: No
- Type: Boolean Expression
<ForEach childName="c">
<Null value="c.Line1" negate="true"/>
</ForEach>
UniqueConstraint
This command performs checks on a collection to ensure the uniqueness of elements.
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"/>
Common validation command parameters as described
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.
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.
- source
- Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
- Mandatory: Yes
- Type: String
- name
- Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
- Mandatory: No
- Type: String
- on
- Description: It references the parameter or expression in a collection
- Mandatory: Yes
- Type: String (Parameter name or expression)
- processAll
- Description: Processes all of the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
<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.
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.
- source
- Description: Address of the logic – it can be ruleset, HTTP, FTP or file system address
- Mandatory: Yes
- Type: String
- name
- Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
- Mandatory: No
- Type: String
- on
- Description: It references the parameter or expression in a collection
- Mandatory: Yes
- Type: String (Parameter name or expression)
- processAll
- Description: Processes all of the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
<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.
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.
- source
- Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
- Mandatory: Yes
- Type: String
- name
- Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
- Mandatory: No
- Type: String
- on
- Description: It references the parameter or expression in a collection
- Mandatory: Yes
- Type: String (Parameter name or expression)
- expect
- Description: Total value that is expected
- Mandatory: Yes if the value is not provided
- Type: Numeric
- by
- 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
- Mandatory: Yes
- Type: String
- processAll
- Description: Processes all of the collection even if logically it can be stopped
- Mandatory: No
- Type: Boolean (true/false)
<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
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.
- source
- Description: Address of the logic. It can be ruleset, HTTP, FTP or file system address
- Mandatory: Yes
- Type: String
- name
- Description: It defines the name of the logic when it is loaded. The name of the logic can be overridden using this setting
- Mandatory: No
- Type: String
- on
- Description: It references the parameter or expression to a collection
- Mandatory: Yes
- Type: String (Parameter name or expression)
- expect
- Description: Total value that is expected
- Mandatory: Yes if the value is not provided
- Type: Numeric
- by
- 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
- Mandatory: Yes
- Type: String
- processAll
- Description: Enforced to process all of the collection even if logically can be stopped
- Mandatory: No
- Type: Boolean (true/false)
<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.
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.
- name
- 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.
- Mandatory: No
- Type: String
- value
- Description: Contains the value or formula
- Mandatory: Yes (either value of ref is required)
- Type: String
- path
- 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.
- Mandatory: No
- Type: String (referencing object property of array index)
- reference
- Description: Reference to the variable name
- Mandatory: Yes (either value of ref is required)
- Type: String
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.
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.
Allows collecting data through a REST API.
- Address: Url and the Url Parameters for the REST API endpoint
- Url: The target URL of the REST endpoint
- Parameters: Url parameters of the REST API call. Use { and } to bindthem to execution context Parameters.
- Selector: Selector of the REST API
- Headers: Header of the REST API
- Verb: Method to call the API (GET, POST, PUT, DELETE, PATCH, HEAD, CONNECT, OPTIONS, TRACE)
- Body: Expression as the Body payload to be sent by the REST call
- Authorization: Credential of the API
- Username: User name for service authorization header
- Password: Password for service authorization header
- Token: Access token of client to communicate to a service end point
- Results
- Multiple: True selects multiple results (multiple objects)
- Result Path: Property’s path expression
- Copy Value To: Refers to a Variable parameter that the call result will be stored into it
CallMethod
When there are objects defined inside a rule, this command can make a call to the object methods.
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.
- method
- Description: Name of the method of the object, which also includes the object reference
- Format
- objectReference.MethodName(param1, param2, param3)
- objectReference.MethodName (In this format, Param commands are mandatory.)
- Mandatory: Yes
- Type: A string in the given format
- return
- Description: A variable in which the method result is stored
- Mandatory: No
- Type: String (name of the variable)
Param
This command passes a value to the method for referencing.
<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.
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.
- contextMode
- Description: Sets the context for the called procedure
- Mandatory: Yes
- Types
- 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
- 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
- resultCopyMode
- Description: This attribute is set when the target procedure has variables that need to be accessed via the root executing procedure.
- Mandatory: Yes
- Types
- None: Does not copy
- AddOut: Copies out-variables
- AddIn: Copies in-variables
- AddBoth: Copies both in- and out-variables
- return
- Description: Sets a value of a parameter as a return value of the operation/call
- Mandatory: No
- Types: String (name of a parameter)
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.
<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>