I am making a SharePoint app with javascript.
I am trying to add a list item to a list I have defined in Visual Studio. I have done this just by adding a list in the solution explorer, and I made some custom columns in the graphical view. This is actually where I suspect my error could be located. Is this how I define my columns? My code looks like this
var oListItem = null;
function createListItem() {
var oList = clientContext.get_web().get_lists().getByTitle('List');
clientContext.load(oList);
var itemCreateInfo = new SP.ListItemCreationInformation();
oListItem = oList.addItem(itemCreateInfo);
clientContext.load(oList.get_fields());
oListItem.set_item('Car', 'My New Item');
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, onQuerySucceeded),
Function.createDelegate(this, onQueryFailed)
);
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
I am able to print out the list and the fields, but I am not able to add the item like this. I get an error telling me:
Request failed. Column 'Car' does not exist. It may have been deleted by another user.
What can I do to be able to add some items to my list? Do I have to define my list otherwise?