0

How would I prevent duplicate entries into a list from being entered based on the status of a different item on the list. For example, I don't want someone to enter an new list item if they have an item with an open status.

Name Status
Jones, Open (new entry not allowed, duplicate value)
Jones, Closed (new entry is ok)

1

I suggest you to deploy an event receiver and handle the event ItemAdding.

public override void ItemAdding(SPItemEventProperties properties)
{
    try
    {
        //statusOpen= your logic to check the status of a different item on the list
        if (statusOpen)
        {
            properties.Status = SPEventReceiverStatus.CancelWithError;
            properties.ErrorMessage = "Error status open";
        }
        else
        {
            base.ItemAdding(properties);
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}
  • or CSOM with PreSaveAction as other answer suggests – Nk SP Apr 21 '15 at 15:01
  • Out of interest, what does base.ItemAdding() actually do and why do you call it only if the event is not to be cancelled? – Submits Apr 21 '15 at 15:38
0

You should create an Event Receiver and handle ItemAdding event.

Inside the handler you can add you validation logic. If it fails you can Cancel the update and take the user to a custom Error page.

Another option is to use Client object model and handle PreSaveAction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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