how to get the current item id for newly created item in SharePoint

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 a requirement to store the current item id in a Field, once we clicked on the custom save button.
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;
 var url = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=ID&$OrderBy=ID desc&$top=1";
$.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) {      
 }
});
}
 </script>
 get the current item id for newly created item in SharePoint using javascript