Validation rules are more advanced rules that you can use to define constraints between attributes within an entity.
Before you begin
You have already created a data model and the business entities and attributes in the data model. For further information, see Creating a data model, Creating business entities in a data model and Adding attributes to the business entity.
About this task
Consider as an example that your data model holds the following entities: Agency, Agent and Region. You want to create a validation rule to make sure that the agent Id is concatenated from the first three letters of its first name and the two first letters of its last name.
To add a validation rule to a business entity, do the following:
In the data model editor, right-click the Agent
attribute and select Set the Validation Rule.
A dialog box pops up.
Enter a name for the validation rule, Check Id in this
example, and then click OK to close the dialog box.
The validation rule is displayed under the Annotations node of the Agent attribute.
Double-click the validation rule to open the Set the Validation
Rules dialog box where you can set the parameters of the
Click the icon to
add a line in the table and then click in the Type column
and select from the list assert or
report according to what type of rule you want to set.
assert elements are instantiated if the XPath
expression evaluates to false and are used to detect
errors, whereas report elements are instantiated if the
expression evaluates to true and are used to report the
existence of an instance.
Click in the Context XPath column and set the Xpath to the attribute for which you want to create a validation rule, Id in this example.
Click in the Expression column and then click the
three-dot button to open the expression editor.
Set the validation rule using the expression editor. Check the XPath functions
online help, http://www.w3.org/TR/1999/REC-xpath-19991116/#corelib, for
information on the right methods to use.
In this example, you need to check that the agent Id corresponds to the concatenation of the three first characters of the Firstname attribute and the two first characters of the Lastname attribute.The dot at the beginning of the rule refers to the context attribute, Id in this example. You must then use the
concatfunction to concatenate the attributes characters which are extracted with a
substringfunction.Click OK to close the expression editor.The validation rule displays in the Expression field.
In the Set the Validation Rules dialog box, click in the
Message column and then click the three-dot button to
open a dialog box. Here you can set up the error message that should be
displayed when trying to save a record that has an agent Id that does not
correspond to this validation rule.
- Select the message language from the language list and then enter the error message and click the plus button to add the message to the list.
Repeat the operation to add error messages in different languages, if required
and then click OK to close the dialog box.
The defined error messages display in the Message column in the Set the Validation Rules dialog box.
- In the Set the Validation Rules dialog box, click OK to validate your changes and close the dialog box.
- Save your data model.