There are multiple ways to prevent adding duplicate records using rulebases. A few solutions follow.
1). Using Duplicate Function : To check if attributes of the current repository are not duplicated.
Use the following action in the rulebase constraint :
<action>
<check>
<explanation>FirstName - LastName pair duplicated !!</explanation>
<information>FirstName - LastName pair duplicated !!</information>
<duplicate>
<var>FirstName</var>
<var>LastName</var>
</duplicate>
</check>
</action>
2). Using the count and distinct function.
Assume there is Repository Parent1 related to Child1. The user adds record p1 related to records c1, c2 in Child1. Now to check if the records in the child are not duplicated :
<declare usage="local">
<var>var1</var>
<link type="relationship_record">
<literal>Child1</literal>
</link>
</declare>
<constraint>
<name>con</name>
<description>con</description>
<usefor/>
<action>
<check>
<explanation> FirstName is duplicated in related repository !! </explanation>
<information>FirstName is duplicated in related repository !!</information>
<eq>
<op func="count"> <var>var1/FirstName</var>
</op>
<op func="count"> <op func="distinct"> <var>var1/FirstName</var>
</op>
</op>
</eq>
</check>
</action>
</constraint>
3). Using the Assign Identity action.
The Assign Identity action does not allow adding duplicate records. Instead, it modifies the existing record.
<constraint>
<name>con</name>
<description>con</description>
<usefor/>
<action>
<assignidentity>
<explanation lang="en">test_assignIdentity_expl</explanation>
<var>mq_sequence_2</var>
<var>FirstName</var>
<var>LastName</var>
</assignidentity>
</action>
</constraint>