AnsweredAssumed Answered

Javascript actions problem

Question asked by ajaywazir on Jul 22, 2008
Hi
I am tyring to execute the following javascript code upon upload content into a folder.



var Olddocname = document.name;
var docname = document.name.substring(0, document.name.lastIndexOf('.'));
var newDocName = docname+"_Released.txt";
var newDocContent = document.content;

var backupFile = space.childByNamePath(newDocName);
var OldDoc=space.childByNamePath(Olddocname);

   if (backupFile != null)
   {
   
    var workingCopy = backupFile.checkout();
        workingCopy.content = newDocContent;
      backupFile = workingCopy.checkin(); 
      document.remove;      
   }
   else
   {
   document.name=newDocName;
   document.addAspect("cm:versionable");
   document.save();
   }

The intent is
/* Try on text files first
//File is to be  uploaded
//File should not be there; else there would be errror by alfresco, so we must delete it after processing.
//Capture upload  Event and run this script
//check if incoming document name_Released.txt exists
// If exists
//{ check it out the file
update contents
check  it in
add version log if any
delete the original file that was uploaded
}
else
{create a new file with the name
incoming document name_Released.txt
make it versionable
add tags;categories if needed
save the file

*/

We have two problems with this
1. The back up document is checked in twice. That means, if the current rev is 1.01, it creates two revs 1.02 and 1.03
2. The original document is not deleted by document.remove;

Any suggestions?
Just to add
logger user is admin/admin
and there are no exceptions thrown by Alfresco?
Ajay

Outcomes