// File Name: move_version.js
// Purpose : Move a file from a folder to a target
// folder (which is parent folder). If file already exists
// in target folder it uses versioning to replace file
// and increase version number.
// Author: Julien Bonjean (firstname.lastname@example.org)
// Creation Date: 2009-02-10
// Last Modified: 2009-02-10 16:26:10 -0500
var sourceFile = document;
var sourceFolder = document.parent;
var targetFolder = space.parent;
var targetFile = targetFolder.childByNamePath(document.name);
if(targetFile == null)
var targetFileWorkingCopy = targetFile.checkout();
targetFileWorkingCopy.content = sourceFile.content;
targetFile = targetFileWorkingCopy.checkin();
Here is the code we are using.It worked well with alfresco 2.1 but with alfresco 3.0. It doesn't work anymore. I think it worked with text file. But with pdf file. The new revision is an empty page. It produce corrupted odt files..etc. I don't know what's wrong. If there is something wrong with this scripts. Or it's just alfresco doing something without telling us?
By the way, the scripts was used to move a file from folder A to folder B. We look if the a file exists with the same name in folder B then we checkout the file…modify the content…then checkin and delete the source file that is now versionned.
Our problem is documented here.
The content property can only handle safely string content. In other words, the binary content get converted to the encoding we're using or the encoding of java most probably utf8. All non-ascii chars get converted to something else having the effect of corrupting versioned files.
We looked in the source code and we can't find any function or property that would allow us to get and set binary content.