Pages

Monday, December 28, 2015

Check If An Item Exists In SharePoint List

How to check if an item exists in SharePoint list using SPServices?

Pre-requisites:





Solution:


Using below shown SPServices code you can check if an item exists or not in a specific list.

You can use JSOM/REST code as well but that would be an asynchronous call, whereas, SPServices is a synchronous call.

Here, in the CAMLQuery, where I have entered “test”, you can dynamically check for the value coming in from the input box or the textbox of your list "NewForm/EditForm.aspx" page or a control added to your custom page.

This code, you can add to your both list’s “NewForm.aspx” or “EditForm.aspx” and even you can add it to your custom page.

In case, if you are adding it to your “NewForm.aspx” or “EditForm.aspx” then you need to put this inside the “PreSaveAction()” function of SharePoint so that before saving/updating, it can be validated.

To know how to use "PreSaveAction" function, please check it here - https://code.msdn.microsoft.com/office/SharePoint2013-Use-of-a27c804f



Hope this helps!
Read More »