0

How can i find what item failed executeQueryAsync add item method ?

this is my code :

var itemArray = [];
var siteUrl = "http://MySite/MM/cm";
var clientContext = SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('xy');

var itemCreateInfo = new SP.ListItemCreationInformation();
oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('FullName', "ali");
oListItem.set_item('CellPhone', "555-666");

oListItem.update();
itemArray[i] = oListItem;
clientContext.load(itemArray[i]);

clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);

function onQuerySucceeded() {
    console.log("item created in : ", oListItem.get_id());
}

function onQueryFailed(sender, args) {
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

I con not find out what item is duplicate in item creation that my query is failed ! if i can find it then i can update it and continue with others !

2

Pass the item you wanted to create, to the failed function with standard JavaScript bind
(supported in InternetExplorer since IE9)

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind

...

clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed.bind(oListItem) );

...

function onQueryFailed(sender, args) {
    var oListItem = this;
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Explained in detail in:

Your Answer

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

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