1

I have used the below code for adding items in a sharepoint list in office 365. Below the line :

this.oListItem = oList.addItem(itemCreateInfo);

whereever oListItem is used am getting an error saying oListItem is undefined. I found this code in a microsoft site. But still am getting an error.

Any advice is appreciated.

got the code from the below URL:

http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8f2a912b-88b8-42b7-b187-c2a6039bf97d/using-javascript-to-add-an-item-to-a-sharepoint-list.

var siteUrl = '/sites/MySiteCollection';

function createListItem() {

var clientContext = new SP.ClientContext(siteUrl);
 var oList = clientContext.get_web().get_lists().getByTitle(' Participant ');

var itemCreateInfo = new SP.ListItemCreationInformation();
 this.oListItem = oList.addItem(itemCreateInfo);

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

 oListItem.update();

clientContext.load(oListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, 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 think the problem may be because of spaces in the list tile. Can you trying removing the spaces in it. .getByTitle('Participant') – Nadeem Yousuf Nov 28 '13 at 6:27
  • I just ran into this except on the line after. Any resolution here? – tnw Feb 27 '14 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.