Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

The code should work I think. You haven't just changed the Title field to Car ? If so, the internal name of the column is still Title, and you need to use that:

oListItem.set_item('Title', 'My New Item');

If not, double check that the internal name of the field is actually Car

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.