Is there a way to append a file with (2) if a file with the same name already exists? Currently, the 'Move a File' connection for Box.com errors out if a file with the same name exists and the entire workflow ends.
Solved! Go to Solution.
Well... there actually -is- a solution, but its tedious and takes a lot of actions. I'm currently doing this for all Box movement functions within my workflows, and have made a component workflow just for box file movement.
1) Store the filename as a variable (will will be disecting this later)
2) Set a variable to track how many times you've been through the loop
3) Use "Box - Get Folder Contents" to store a collection of all objects in the target folder.
4) Begin a loop that will exit once a unique filename has been determined
5) Use "Check if item exists in a collection" to determine if the intended filename is already in the target folder (from step 3)
6) Use "Logic and flow - Branch by condition" to have a separate path for an OK filename vs. a conflicting filename
7) on the OK file name path, simply move the file and exit the loop
8) on the conflicting filename path, break apart the filename into 2 separate variables using Regex. The base filename should be a regex of \.[^.\\/:*?"<>|\r\n]+$ The file extension should be a regex of [^.]+$
9) create a new filename by adding the filename & "_" & the LoopCounter & the filenameExtension.
10) end the loop
By modifying the filename in step 9, the next time the loop completes the filename will now be named "mytextfile_1.txt" after the first loop if there is already a "mytextfile.txt" in the folder. It will repeat the loop until a conflict is not present.
For anyone that is using a solution similar to what I described above; please be aware that Nintex currently only supports searching through 200 entries in a folder. if you have more than 200 items (files + subfolders) then the Nintex connector will act as if there are only 200. This can lead to errors where the WF doesn't realize there is a duplicate file name, but the duplicate is past the Box API's pagination value (200).
I've started a feature request to add support for paginated responses in Connectors. Feel free to add a vote to that request if you use any methods like I described to loop through contents.