We would like to add a unique constraint to one of our custom fields in Rhythmyx. Is there a straightforward way to do this? Rx implements this for sys_title already. Is there code we can leverage from that? Or would we have to write a custom extension? If we write an extension, what API would we employ to do the lookup to check for a row already containing the entered content? Examples?
This would be a nice option to have out of the box in the workbench … checkbox for “unique”.
Thanks for the tip, Guillaume. I just tried applying that extension, but it did not have any effect. I can enter two content items with the same value on the field in question without error. Did you have to do anything else to activate this, other than restart the Rx instance?
It turns out the “sys_ValidateUniqueName” validator is broken as of 6.5.2. It is in the queue to be fixed in an upcoming release. We also learned that this validator only checks the current directory for duplicate entries (by design).
What we wanted was a check for field uniqueness across all content items with the given field. We had to implement that as a custom validation rule. IMO, this should be offered as a standard validator in the core product.
[QUOTE=stephenh;1613]It turns out the “sys_ValidateUniqueName” validator is broken as of 6.5.2. It is in the queue to be fixed in an upcoming release. We also learned that this validator only checks the current directory for duplicate entries (by design).
What we wanted was a check for field uniqueness across all content items with the given field. We had to implement that as a custom validation rule. IMO, this should be offered as a standard validator in the core product.[/QUOTE]
The problem here is that everybody has their own requirements. I can certainly see that some customers will need uniqueness across the whole system, but others will want uniqueness only within a particular site (for example).
Since there are many options, I think our goal should be to make this flexible and easy to extend, rather than to cover every possible possibility “out of the box”.
That said, how difficult was it for you to implement a custom validator? What do we need to do to make that process easier?
We are running 6.5.2 with the lastest patch. The problem we saw was that the validation rule was not executed, or at least presented to the UI, unless another error was present on the page. Maybe this is unique to our configuration, but it’s on the devel bug list regardless.
Dave,
Sharyn found your post on the forum which was helpful in figuring out how to do this.
Having this doc and code set in the product’s Docs would be handy for a start. I agree that variations could exist on the unique constraint rule. But at it’s heart, it’s pretty common. Just look at any db implementation for proof of this! You could take the approach that setting a unique flag on a property in the Content Workbench would add a unique constraint on the table, and then have the app backing the content explorer catch any of these exceptions and convert them into error messages for the UI. But that might be too course grained.
We wound up writing a custom validator based off your examples for the specific property in question. We plan to refactor this at some point to accept any property from any table. For now, what we have works. The general version might make a good reference implementation for others. Care to give it a go?
Sorry to pull up an old post, but I am noticing that we are having this same issue. Whenever we apply the sys_validateUniqueName() to a field it will only present an error to the UI if there is another error present. Was there ever a fix presented for this? I couldn’t find one on here, and it wasn’t in the current patch list. We are on 6.5.2 [RX-14225]
According to Tech Support, this was to be fixed in 6.6. So what you are seeing is to be expected until you upgrade or press for a patch including this fix.