Skip to main content

I have a workflow that occasionally fails because, according to the NWC error message, "A file attachment with name '[File name].pdf' already exists" (in the SharePoint list where instance data is being written from NWC). This is in a workflow where users submit requests to pay vendors. One thing they can do on the form, and they often do, is attach some kind of documentation (such as an invoice). The documentation is attached to the item in a SharePoint list.

 

We've had a couple of instances where the user attached a file with the same name as a file they had attached in a previous instance, such as "Invoice - John Smith.pdf," and the workflow failed due to the above reason. This is happening even though the attachments are in different items in the list.

 

So I guess what I want to do is search the SharePoint list and identify any attachments anywhere in the list that have the same filename as the attachment in the current NWC instance, and if there are any, rename one of the documents so that the filenames are no longer identical. Not sure how to do this.

 

I know we have the NWC actions that work with files/attachments in SharePoint but I'm not sure how (or if) to use them for something like this. Any help would be appreciated.

@Sven Could you perhaps assist here?


You could try the Rename a file action https://help.nintex.com/en-US/nwc/Content/Designer/Actions/SharePointOnline-RenameFile.htm to rename files dynamically using the DateTime for example. I am not sure if this is possible before saving to SharePoint but it might be.

While this wouldn't prevent your problem from occurring, it could maybe help identify if you have duplicates. (Below isn't heavily tested, just confirmed to be working when using a collection of files returned from DocuSign)



 



You could use this regular expression to get all the filenames stored in an NWC collection:





Signed Files: Collection of files



Pattern: (?<="fileName\":\")[^"]*(?=\")



AllFileNames: Output collection that should contain all the filenames in the collection.



 



You could then maybe loop through the AllFileNames collection to see if any of those files also exist on Sharepoint. If so, maybe rename the SharePoint file before uploading.


@bsikes@MeganGo - thank you for your suggestions. Unfortunately it doesn't seem to me that the Rename a file action will work - it seems to be designed to rename files in a SharePoint document library, not files attached in a list.



Not sure how I could rename a file before uploading it to SharePoint either. I'm trying to use @bsikes' regular expression idea to capture the file names, but then what? Assuming I can identify duplicates in the SharePoint list, how would I then rename the file from the NWC workflow before it's uploaded to SharePoint?



Thanks again to all for your help.


I was hoping you could use the regular expression idea to figure out what file names you had in NWC, then check for those files in Sharepoint and rename them if there's any duplicates. I didn't realize the "Rename a file" action doesn't work with files attached to a list.



 



As far as I know, there's not a way to rename the files in NWC. But you could maybe accomplish renaming an NWC file through a round-a-bout process.





  1. You could maybe upload the file to Sharepoint (not on the list)


  2. Rename that file to have a unique identifier in the name (Such as a date/timestamp)


  3. Get that uniquely named file from Sharepoint into NWC


  4. Upload that file to the Sharepoint list


  5. Delete renamed file on Sharepoint that was renamed in step 2.




 



Not by any means an ideal solution, but I think it would work. 


By Jove, @bsikes, I think you've got it! As you say, that's a bit of a roundabout solution, but it does work. There doesn't seem to be an NWC function for deleting a SharePoint file, as per your step #5 (looks like you can only delete a list, a site, or items in a list), but I can live with that. I've added the date, reformatted to text, as part of the new filename - I wanted to include the timestamp too, but the colons in the time make the new filename invalid. I guess there's probably a RegEx to reformat those colons to periods or something, but I know next to zip about RegEx grammar.



Anyway, thanks very much for your help!


Reply