What is the best approach to enforce unique values in a Module?

2025/07/31 1:01 PM

What is the best approach to enforce unique values in a Module? For example, consider a list of shops with a field named 'ShopCode'. We want to make sure that the content editor can only enter unique ShopCodes.

One solution is to create a validation rule, such as 'UniqueShopCodeValidationRule', which checks if an item with the entered ShopCode already exists and apply this rule to the 'ShopCode' field using the field editor. A drawback is that the 'UniqueShopCodeValidationRule' could also be applied to other fields, although the advantage is that we can provide the content editor with a message if the shop code already exists.

With the IInfoObjectEventHandler we could also perform this check, but I don't see how we could display a message to the content editor indicating that the shop code already exists. Am I overlooking another possible approach?Describe your question...


Environment

Tags:
Custom modules

Answers

2025/07/31 1:51 PM

A few questions

  1. How are new custom object types being created? (custom application UI, programmatically through background services, from visitors in website channels)
  2. Have you considered making your validation rule more generic by adding a validation rule properties class which can target different fields for uniqueness?
2025/08/05 8:51 AM
  1. The CreatePage and InfoEditPage are being used to insert new and edit the objects.
  2. This could indeed be a possibility, I will investigate this.

Thanks for thinking along!

2025/08/06 3:42 AM

For your #1 scenario you can customize the form submission handling in the create and edit page virtual methods, perform custom validation, and return a failed result in the case that the uniqueness constraint isn't fulfilled.

But option #2 is probably the best choice if it fits your requirements.

To answer this question, you have to login first.