Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

custom list - REST service

$
0
0

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



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>