Thursday, 31 July 2014

SharePoint REST file attachment error status "Conflict"

status Code: 409
status Text :conflict

Root Cause:After doing some updates to List Item using CSOM or REST, list item version will update, the list item instance which you are having will not work.
Solution: Get latest list item instance
Code Ex:

var listName = "MyList";
var idd = "20";
var objCtx = new SP.ClientContext.get_current();
var MyList = objCtx.get_web().get_lists().getByTitle(listName);
objCtx.load(MyList);
var theList = objCtx.get_web().get_lists().getByTitle(listName);
var listItem = theList.getItemById(idd);
listItem.set_item("Title", "Update");
listItem.update();
objCtx.load(listItem);
objCtx.executeQueryAsync(
function () {
//File Upload
//I have 5 attachments, I am going to upload 5
for (var i = 0; i < 5; i++) {
uploadFile(i);//My custom function to upload file.......
//Reload Item-Start
var objcontext = new SP.ClientContext();
var MyList1 = objcontext.get_web().get_lists().getByTitle(listName);
listItem = MyList1.getItemById(idd);
objcontext.load(listItem, "Title");
objcontext.executeQueryAsync(function () {
console.log("New Item instance Done");
}, function (sender, args) {
console.log("New List Item instance Fail" + args.get_message());
});
//Reload Item- End
}
//File Upload Done
},
function (sender, args) {
console.log(args.get_message()+ "Error while update");
}
);
view raw gistfile1.js hosted with ❤ by GitHub