1

when a user is trying to insert an item that already exist in the list - I want to know about it and an email will be send to me. so I want to write a caml query that will contain the value the user trying to insert in the list and will compare to other items in the list. the query:

<Where>
  <Eq>
     <FieldRef Name='Name' />
     <Value Type='Text'>[The value the user insert in the list]</Value>
  </Eq>

but how can I insert to the value of what the user wrote?

is this possible? how? thank you!

  • 1
    can u explain more? you want to insert the value into the list ? – SharePointMan Apr 22 '14 at 8:26
4

I think you would be better of if you would set Enforce Unique Value as true for the required columns.

P.S. You can do that by going to the List Settings -> Select the column -> Enforce unique values as True

4

You can use SharePoint Event Receivers.. ItemAdding is the event receiver you are looking for..

Please have a look at:

Creating SharePoint 2010 Event Receivers in Visual Studio 2010

  • I can't use the Event Receiver: ItemAdding, I use SP Online. – user25290 Apr 22 '14 at 9:50
1

not sure what you mean but if you mean how to query using the user value than you just have to write it this way

<Where>
  <Eq>
     <FieldRef Name='Name' />
     <Value Type='Text'>"+ [The value the user insert in the list] + "</Value>
  </Eq>
  • I will explain more: when a user is trying to insert an item that already exist in the list - I want to know about it and an email will be send to me. so I want to write a caml query that will contain the value the user trying to insert in the list and will compare to other items in the list. – user25290 Apr 22 '14 at 9:01
  • you perform the above query and take viewfield as Name and compare the item with your value. if its equal than give an alert message and write a logic to send email – SharePointMan Apr 22 '14 at 9:04
  • then Event Receivers -as suggested by @Arsalan- are the way – MdMazzotti Apr 22 '14 at 9:16
  • 1
    @MdMazzotti event receiver is the best approach if it was SP on premise. But he has tagged SP online.Is there any way to send email from event recievers in SP online?.Also is it recommended to write Event receivers for online as it will be sandbox code – Unnie Apr 22 '14 at 9:40
  • @Unnie you're right, I didn't notice the tag. By the way, I think you meant "it is not recommended to.." – MdMazzotti Apr 22 '14 at 9:46
1

Forget CAML query in this case. Use a workflow instead. Setup a workflow on the list that will trigger every time a new item is added.

In the workflow you can setup logic which checks if the newly added items Title property equals an existing one and then send the e-mail accordingly.

This can easily be done using SharePoint Designer, which is compatible with SharePoint Online.

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.