Tuesday, March 8, 2016

Getting item id from newly created item

function CreateListItemWithDetails(listName, webUrl, newItem) {

    var item = newItem;

    return $.ajax({

        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",

        type: "POST",

        contentType: "application/json;odata=verbose",

        data: JSON.stringify(item),

        headers: {

            "Accept": "application/json;odata=verbose",

            "X-RequestDigest": $("#__REQUESTDIGEST").val()

        }

    });

}

 

CreateListItemWithDetails(listName, webUrl, newItem)

    .then(function(data){

        //success callback

        var NewlyCreatedItemId = data.d.ID;

    }, function(data){

        //failure callback

    });

No comments:

Post a Comment