Skip to main content
Added an example.
Source Link
Gilgamesh
  • 261
  • 2
  • 11

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.

Edit, here's a working example:

function create(i) {

    var clientContext = new SP.ClientContext.get_current();

    var oList = clientContext.get_web().get_lists().getByTitle('SomeList');

    var itemCreateInfo = new SP.ListItemCreationInformation();

    //note that we are using var to make a local variable.
    var oListItem = oList.addItem(itemCreateInfo);

    oListItem.set_item('Title', 'Item '+ i );
    oListItem.update();
    clientContext.load(oListItem);

    var SaveEmployeeSuccess = function() {
        console.log('item created'+this.get_id());
    }

    var SaveEmployeeFailure = function() {};
    clientContext.executeQueryAsync(
        Function.createDelegate(oListItem, SaveEmployeeSuccess), 
        Function.createDelegate(oListItem, SaveEmployeeFailure));

}

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.

Edit, here's a working example:

function create(i) {

    var clientContext = new SP.ClientContext.get_current();

    var oList = clientContext.get_web().get_lists().getByTitle('SomeList');

    var itemCreateInfo = new SP.ListItemCreationInformation();

    //note that we are using var to make a local variable.
    var oListItem = oList.addItem(itemCreateInfo);

    oListItem.set_item('Title', 'Item '+ i );
    oListItem.update();
    clientContext.load(oListItem);

    var SaveEmployeeSuccess = function() {
        console.log('item created'+this.get_id());
    }

    var SaveEmployeeFailure = function() {};
    clientContext.executeQueryAsync(
        Function.createDelegate(oListItem, SaveEmployeeSuccess), 
        Function.createDelegate(oListItem, SaveEmployeeFailure));

}
added 6 characters in body
Source Link
Robert Lindgren
  • 24.5k
  • 12
  • 53
  • 79

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItemoListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItemthis.oListItem is a global variable. try using var oListItemvar oListItem instead and then passing the reference to the item into your success method in some manner.

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.

Source Link
Gilgamesh
  • 261
  • 2
  • 11

Cascading async functions do work, since your example is working fine. It's only how your are handling responses that's problematic.

It looks like the problem is how you are referencing oListItem.

Each time you iterate though the loop you are changing the same reference to oListItem since in your case this.oListItem is a global variable. try using var oListItem instead and then passing the reference to the item into your success method in some manner.