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 am creeting an event reciever that ensure that my list has unique items based on two columns. If I find a duplicate I wish to do one of the following:

  1. display a dialog which states a duplicate has been found, in that dialog display both items and a text box next to each so that the user can edit whichever one they deem should change.

  2. send user back to edit form with the appropriate fields highlighted and an error message stating a duplicate has been found.

Currently the receiver is displaying the error message in a new window which is not useful and quite "ugly"

0x81020089The Sequence Number you have entered already exists for an item in this rulebook Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: 0x81020089The Sequence Number you have entered already exists for an item in this rulebook

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

share|improve this question

2 Answers 2

Hmm, I'd think about a different approach.

The problem is that the events that you can catch and notify the user of a problem are the synchronous ItemAdding/ItemUpdating. At this point the item hasn't been added to the list. So therefore its going to be difficult to tell the user that they have a duplicate and also allow the item to be added to the list.

How about detecting the duplicate before the user has created the list item?

You could create a custom edit form which captures the user's input and uses the Client Side Object Model to detect if the item has already been created and then guide the user from there?

Anyway, for completeness to redirect the user in SharePoint 2010 you need to set two things within the SPItemEventReceiver.ItemAdding function (http://msdn.microsoft.com/en-us/library/Microsoft.SharePoint.SPItemEventReceiver_methods.aspx).

Here is the function signature:-

public virtual void ItemAdding( SPItemEventProperties properties )

The properties object needs to have the following set:-

  • properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
  • properties.RedirectUrl = {your url}
share|improve this answer

I think you have two options here:

  1. As @Simon Doy mentioned, you can create custom new\edit form and perform some javascript checking. You should create ItemAdding event receiver and do server validation in addition to javascript (because smart user can tamper post data).
  2. Another option also involve creating custom new\edit form. You should create custom rendering template and implement custom SharePoint SaveButton control and override OnBubbleEvent method. In this method you can perform any validation using SPContext.Current.ListItem and some javascript on IU maybe. You can use reflector to investigate how out-of-the box SaveButton work.
share|improve this answer

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.