any way to move files between folders and either o...
# suitescript
d
any way to move files between folders and either overwrite or rename if there is a name conflict ... atm the move seems to outright fail (using
file.folder = ???
and then
file.save()
r
Can't say for sure without knowing your use case in more detail. If you are happy to overwrite conflicts then I believe the following should be pretty close to what you need. Var fileobj = file.load('yourFileId'); fileobj.folder = newFolderId; fileObj.save() If you want to rename if there is a conflict, I think you will need to use a saved search in the script to check for what files already exist in your target folder. I think the Folder saved search type is the right one from memory, it has access to the files within the folders.
Just reread your question and I'm wondering if the problem is using 'file.folder' which is conflicting with the alias of the N/File module which would typically be 'file'.
d
sorry that was meant to be
Copy code
var fileObj = file.load(fileId);
fileObj.folder = folderId;
fileObject.save()
and as I said above, it doesn't seem to overwrite, it just fails
r
Ah, I thought I had something that does this already but i've just tracked down my script. The only workaround I found was to find the existing file with the same name and replace the contents of the existing file in the destination folder. (my file was just a CSV). Alternatively, you could delete the existing duplicate in the destination folder then it should allow you to move your new file in. If you are not already using one, I'd recommend using a map/reduce script if you are doing this in bulk to avoid governance limits. Sorry, that's the best I can do.
d
Thanks, I ended up creating a function to check the move worked, by loading the file and comparing fileObj.folder to folderId and if that came back false, renaming the file and move it again
r
Good idea, glad you found a solution.