I have a need to update multiple list items via CSOM. I found
http://social.msdn.microsoft.com/Forums/en-US/17447ba4-8d59-48c4-b784-859dee38d366/client-object-model-ecma-update-list-items?forum=sharepointdevelopmentprevious
and copied the code exactly at first with no success, no errors. I've tried to tweak it to get something to work and while the code below shows me all the alerts that the update happens, the list items themselves are not updated.
Can anyone point out where my error is?
var siteUrl = '/sites/PortalCollabPri/JMRTesting'; function retrieveListItems() { var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('IT Training Waitlist'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Is_x0020_Eligible\'/><Value Type=\'Integer\'>1</Value></Eq></Where></Query><RowLimit>100</RowLimit></View>'); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded(sender, args) { var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); var context = new SP.ClientContext(siteUrl); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title'); oListItem.set_item('Eligibility_x0020_Score', 100); alert('set eligibility score on ' + oListItem.get_id()); //SHOWS AS EXPECTED oListItem.update(); alert('and updated'); //SHOWS AS EXPECTED context.executeQueryAsync(Function.createDelegate(this, this.on_myUpdate_Success), Function.createDelegate(this, this.on_myUpdate_Failure)); function on_myUpdate_Success() { alert('updated OK'); //NEVER SHOWS } function on_myUpdate_Failure() { alert('Nope, not updated'); //NEVER SHOWS } } alert(listItemInfo.toString()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } retrieveListItems();
- Thank you. Respectfully, Janette M. Ricker