0

I have a SharePoint hosted app that creates a list instance. I'm trying the simple task of creating a list item but it doesn't work. No errors are displayed and I am not able to get into the success or failed methods when debugging.

function createListItem(appwebUrl) {
     var clientContext = new SP.ClientContext(appwebUrl);
     var oList =   clientContext.get_web().get_lists().getByTitle('CustomList');

     var itemCreateInfo = new SP.ListItemCreationInformation();
     this.oListItem = oList.addItem(itemCreateInfo);
     oListItem.set_item('Title', 'My New Item!');
     oListItem.set_item('CustomField Text', 'Hello World!');
     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've also tried this with REST and the same thing occurs. No error, it just doesn't work. What's up with my App?

1 Answer 1

0

First make sure the function is getting invoked properly. Then change below

this.oListItem = oList.addItem(itemCreateInfo);

to

oListItem = oList.addItem(itemCreateInfo);
5
  • Remove "this." didn't change anything. I'm invoking the method on a button click like so createListItem(_spPageContextInfo.siteAbsoluteUrl); Commented Aug 3, 2016 at 21:41
  • Have you tried adding some alert statement just to make sure how far it goes. Commented Aug 3, 2016 at 21:46
  • I can debug right up to "clientContext.executeQueryAsync". The alerts shown in the code never fire. Commented Aug 3, 2016 at 21:50
  • Remove this from the functions.. Also check if the item actually got created or not. Commented Aug 3, 2016 at 22:29
  • I removed 'this' as you can see in my above edit. The item is definitely not created Commented Aug 5, 2016 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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