My objective is to add a new item in a SharePoint list (Form) using REST API.
My current code is:
function AddData() {
var listName = "Form";
CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, function () {
console.log("New Item has been created successfully.");
}, function () {
console.log("Ooops, an error occured. Please try again.");
});
}
function CreateListItemWithDetails(listName, webUrl, success, failure) {
var itemType = "SP.Data.FormListItem";
var item = {
'__metadata': { "type": itemType },
'Title':document.getElementById('explorationescalation').value,
'Capex Escalation':document.getElementById('capexescalation').value,
'Opex Escalation':document.getElementById('opexescalation').value,
'Abandonment Escalation':document.getElementById('abandonmentescalation').value,
'Oil Price ($/bbl)':document.getElementById('oilprice').value,
'Gas Price($/mcf)':document.getElementById('gasprice').value,
'Opex ($/bbl)':document.getElementById('opex').value,
'LRP':document.getElementById('lrp').value,
'HRP':document.getElementById('hrp').value,
'Block Type':document.getElementById('blocktype').value,
'Production Sensitivity':document.getElementById('productionsensitivity').value,
'Capex Sensitivity':document.getElementById('capexsensitivity').value,
'Opex Sensitivity':document.getElementById('opexsensitivity').value,
'WACC':document.getElementById('wacc').value,
'Abandonment Rate':document.getElementById('abandonmentrate').value,
'IT Rate':document.getElementById('itrate').value,
'MAT Rate':document.getElementById('matrate').value,
'FX Rate (INR/$)':document.getElementById('fxrate').value,
'NCCD (INR/MT)':document.getElementById('nccd').value,
'BBL to MT':document.getElementById('bbltomt').value,
'Discount Date':document.getElementById('discountdate').value,
'Regime':document.getElementById('regime').value,
'Block Name':document.getElementById('blockname').value,
'Project Name':document.getElementById('projectname').value,
'Project Description':document.getElementById('projectdescription').value
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_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()
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
However when I tried to create item using the button. I get error message in network tab while inspecting element:
"The property 'Capex Escalation' does not exist on type 'SP.Data.FormListItem'. Make sure to only use property names that are defined by the type."
with Status Code 400 of the post request. All of the above columns are already available in the list and I've double check the spellings, white spaces and data type of columns which is also correct.
Further if I comment out all of the item and values except "Title" then I can get the list item created successfully with only column Title updated.
I've also checked the request payload and it is correct.
What could be the reason that it is not able to update all fields but one? Please help!