Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've got a custom list that contains multi collumns. The validation is made by a custom contenttype. Now I want a combination of two columns to be unique. Until know I did not found a way to solve this problem with on-board functions, so my idea was to use the eventreceiver or a customcontenttype.

What I tried:

ListEventReceiver

public override void ItemAdding(SPItemEventProperties properties)
       {

           if (properties.AfterProperties["a1"].ToString() == properties.AfterProperties["a2"].ToString())
           {
               properties.Status = SPEventReceiverStatus.CancelWithError;
               properties.Cancel = true;
               properties.ErrorMessage = "Failure";
           }
           base.ItemAdding(properties);
       }

It works fine, but the error message is not show as a validation error. It is a new errorpage. enter image description here

CustomContenttype

If I try to validate in a custom contenttype I can not access the value of an other field from the contenttype. So I can not compare two fields or check they are unique.

share|improve this question
add comment

2 Answers 2

Could this be achieved by using a formula within the list validation settings?

Got to your List and select List Settings > Validation Settings. Use the below formula:

=[a1]<>[a2]

There is also an area for entering a user message for the validation error.

share|improve this answer
add comment

I think the only answer would be to look at doing this in Javascript on the client side.

I would also like to find a way to do this in server code and have it return a validation indication of an error, something like a "*" instead of a huge error page that cancels the entire entry.

Let me know if you have found your answer!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.