Coming from the SQL world, it was frustrating to not have the ability to enforce uniqueness on more than one field. After searching many posts, I came up with a modified version of what was proposed in this post.
1. Create a calculated field concatenating the fields to be checked.
UniqueField = field 1 & field2
2. Setup the self join on the calculated field.
3. Create another field
PKCounter = Count ( UNIQUE_Table::__pkID )
4. Create an Object Name for the last field that is part of the concatenated field that will be inputted into on the layout.
ObjectNameField2 = ONField2
5. Create an Object Name for the next field to be entered after field2.
ObjectNameNxtField = ONNxtField
6. Create a script similar to the one in Done.pdf above, but instead does the following:
Commit Records/Requests[ No dialog ]
If [ STATIC_Table::PKCounter > 1 ]
Show Custom Dialog [ Title: "Unique Check Failed"; Message: "The combination of field1 and field2 must be Unique. Choose Revert to change the record or Delete to delete it."; Buttons: “Revert”, “Delete” ]
If [ Get (LastMessageChoice) = 2 ]
Delete Record/Request
Else
Go to Object [ Object Name: "ONField2" ]
End If
Else
Go to Object [ Object Name: "ONNxtField" ]
End If
Exit Script [ Result: 0 ]
6. On the layout to be used for data input, go to the field2 and put an OnExit Trigger to perform the script.
You do need to take into account any required fields in the table and when they are validated, since the commit will throw validation errors if those other fields are not filled in. That is the reason for the other object named field. It is a required field, but only validated when the user modifies it. When it is set to always validate, you will get an error on the initial commit.