I used the following function to add multiple attachments to SharePoint list items created at the same time through a form

function AddAttachments(itemID) {
    //Retrieving all the files which are available in an Array, Created  this Array in 
    //the above step(Step 2)
    for (var i = 0; i < fileCount; i++) {
    if (fileData[i] != '')
             operation: 'AddAttachment',
             async: false,
             listName: 'Documents',
             listItemID: itemID,
             fileName: fileName[i],
             attachment: fileData[i],
             completefunc: function (xData, Status) {

The code above works 90 percent of the time. However I have noticed that sometimes if I add 3 attachments to a list item , then only 2 get added and the third attachment is not getting added at all even after a long time. I have a form that uses the above code and through that form I am able to create multiple list items at once with multiple attachments. The requirement is that all the attachments must get attached to each of the list items created to the form. I have noticed that 90 percent of the time things are fine, but there are occasions where like maybe 1 attachment does not get added to one of the list items , although it gets added to the other list items. I did not see any error (at least in the browser).

it is unreliable

I have tried with the REST approach too (to add attachments to SP list items) but I have noticed the same issue there also, Is this because the SharePoint item gets created first and then the attachments get added to it in an asynchronous manner, I am not sure..

Does anyone here experienced this issue ? I have not seen anything on Google search about this unreliability issue. Please share..

  • The best clue about this error would be in ULS logs on the server if it is SharePoint on premises and you can access. Can you again check in Google Chrome console and network tabs for any error? Lastly, make sure the file names are different. If file name already exists then SharePoint will not add it to the list item. – Ahmad Zia Nov 25 '17 at 7:29
  • thanks Ahmad, that was helpful.I have observed that adding attachments using client-side (SPServices or REST) is unreliable. I just wanted to see if anyone out there was experiencing this issue. I will check the logs and the network and if I come across something I will post it here. thanks again.. – vivek m Nov 27 '17 at 16:11
  • i ran some more test and each time closely watching the network tabs in IE and I came across 2 errors a) when there are some bad characters in the file name gives this error - The file or folder name contains characters that are not permitted. Please use a different name b) there is a network error - XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3. – vivek m Nov 30 '17 at 19:17

Your Answer

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

Browse other questions tagged or ask your own question.