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!
Pre-requisites:
- JQuery library - To download or to know more info on JQuery, please check here - https://jquery.com
- SPService library - To download or to know more info on SPServices, please check here - https://spservices.codeplex.com
- Basic knowledge of CAML query - To know more info on CAML, please check here - https://msdn.microsoft.com/en-us/library/office/ms426449.aspx
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!
No comments:
Post a Comment