/ Getting the item type for the list function getListItemType(name) { return "SP.Data." + name[0].toUpperCase() + name.substring(1) + "ListItem"; } // Adding a list item with the metadata provided function addListItem() { listname = "Sample"; url = "http://xxxxxxx:12794"; metadata = "Title" + ':' + "New Title"; alert(metadata); var test = getListItemType(listname); alert(test); // Prepping our update var item = $.extend({"__metadata": { "type": getListItemType(listname) },"Title": "New Title" }); //var metadata = “{ ‘__metadata’: { ‘type’: ‘SP.Folder‘ }, ‘ServerRelativeUrl’: ‘/” + serverRelativeUrl + “‘}” alert('hi'); alert(item); // Executing our add $.ajax({ url: url + "/_api/web/lists/getbytitle('" + listname + "')/items", type: "POST", processData: false, contentType: "application/json;odata=verbose", data: JSON.stringify(item), headers: {"Accept": "application/json;odata=verbose" }, success: function (data) { alertt("Added successfully");// Returns the newly created list item information }, error: function (data) { alert("Failed operation"); } }); }
↧
Add new item to custom list using sharepoint 2013 REST API
↧