Closed vincent-chan-hk closed 6 years ago
Hi @vincent-chan-hk ,
This method takes the individual items as parameters, it does not take an array. If you need to supply an array of files you can do so in several ways. The first is to use the spread operator if that is an option in the browsers you are supporting:
const tmpdelFileList = ["TDSUpdate.txt", "AngularJSAttachment.txt"];
$pnp.sp.web.lists.getByTitle("Generic").items.getById(3).attachmentFiles.deleteMultiple(...tmpdelFileList).then(_ => {
console.log("done");
});
If that is not an option you can fall back on the apply method as shown here:
const tmpdelFileList = ["TDSUpdate.txt", "AngularJSAttachment.txt"];
const attachments = $pnp.sp.web.lists.getByTitle("Generic").items.getById(3).attachmentFiles;
attachments.deleteMultiple.apply(attachments, tmpdelFileList ).then(_ => {
console.log("done");
});
I hope you can now find the function useful.
Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July, 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible, or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!
Oh! Great! You save my little life as I prepared to modify the code for iterating the SP-PNP-JS single deletion. But I found that if I am using ... for (i = 0; i < $scope.delFilesList.length; i++) { w.lists.getByTitle("Project Request Initiation").items.getById(projectDetailId).attachmentFiles.getByName(delFilesList[i]).delete(); } It will raise error. It seems that SP-PNP-JS Single Delete function cannot trigger multiple times in short period of time? It is very strange.
Anyway. really Thank for your help as your answer solved my problem. So, I can have a sleep at tonight. Thank you very much!
Great, going to close this as answered. Do please considering migrating to the new libraries when you can. Thanks!
Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your needs please complete the below template to ensure we have the details to help. Thanks!
Please check out the Developer Guide to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.
Category
[ ] Enhancement
[X ] Bug
[ ] Question
Version
Please specify what version of the library you are using: [ 3.0.8 ]
If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.
Expected / Desired Behavior / Question
Observed Behavior
multiple delete function will convert my String Array into UNEXPECTED Single Array as below:
exceptions.js:24 Uncaught (in promise) Error: Error making HttpClient request in queryable: [400] at new ProcessHttpClientResponseException (exceptions.js:24) at core.js:37
https://XXX.sharepoint.com/sites/debug/_api/web/lists/getByTitle('DebugList')/items(208)/AttachmentFiles('TDSUpdate.txt,AngularJSAttachment.txt')
My String Array ["TDSUpdate.txt", "AngularJSAttachment.txt"] has been converted to AttachmentFiles('TDSUpdate.txt,AngularJSAttachment.txt'). So, this function is not useful as we need to hard cord the filename???
Steps to Reproduce
Copy the code below into a XXX.aspx and upload it to SharePoint Online for testing. Remember to create a SharePoint List by matching the Internal Title name:
Thank you!