Monday, November 3, 2014

Check item exists based on a column value using REST API

<script type="text/javascript">
function PreSaveAction() {
var result = false;
var value=$("select[title=MyColumn] option:selected").text();
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('MyList')/Items?$select=LinkTitle,MyColumn/Title&$expand=MyColumn&$filter=MyColumn/Title eq '" + value;
$.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>

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...