Hi,
I am trying to use REST services to check if an item already exists in a custom list. I tried the below code in new form.aspx, added a script editor:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script type="text/javascript">
function PreSaveAction() {
alert("HI");
var result = false;
var value = $(":input[title='title']").val();
alert(value);
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('TList')/items?$select=*&$filter=Title eq '" + value
alert(requestUri);
$.ajax
({
url: requestUri,
type: "GET",
cache: true,
async: false,
headers:{"ACCEPT": "application/json;odata=verbose"
},
success: function (data) {
if($(data.d.results).length == 0)
result = true;
else
alert("Retry!!!");
},
error: function () {
}
});
return result;
}</script> I am getting alert as "Hi", and then "undefined". How to get the value of Title and is the "requestUri" correct ?
I am getting error as "$" is undefined
How to fix this?
Thanks