In this article we can able
to see how to get the current item id for newly created item, using REST API
and JQuery.
We are having filed with
name “RequestID” and couple of fields and having a custom button.
Call this function on
“getNewRequestItemID” button click and use the below code.
<script
type="text/javascript"
src="/Dotnetsharepoint/SP2013/SiteAssets/jquery-1.11.0.min.js"></script>
<script
type="text/javascript">
$(function () {
var listname = "YOURLISTNAME";
function
getNewRequestItemID(listname){
var currentitemid=0;
var siteURL =
_spPageContextInfo.webAbsoluteUrl;
$.ajax({
url: url,
method: "GET",
async: false,
headers: { "Accept":
"application/json; odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
currentitemid = data.d.results[0].ID;
$("input[title =
'RequestID']").val(currentitemid);
}
},
error: function (data) {
}
});
}