Dynamics CRM 2011 How to set a row field unique?

I want to add the "Single Line of Text" field to my custom object, which must be unique. How can I get Crm to throw an exception to me when I try to create a duplicate value record?

+4
source share
3 answers

You need to create a plugin for this requirement that handles the Pre-Create / Pre-Update step for this object. In this plugin you should check if the passed value is unique or not. If this is not the case, you will throw an exception that cancels the operation and displays a dialog to the user (if the plugin works synchronously).

throw new InvalidPluginExecutionException("Value passed for 'attribute' is not unique."); 
+7
source

You cannot do this through configuration as far as I know.

You will need to use some client code to query the existing values ​​for this field to find out if the new value entered is unique. You can use something like jQuery and the REST CRM service (ODATA) to perform asynchronous field validation; this may not be instantaneous, you may need to consider how this is presented to the user.

Alternatively, you can do this using a workflow, but it will be even less instantaneous - it probably should be called after saving.

+1
source

Another option is to create a unique SQL index directly in the database.

-1
source

All Articles