AnsweredAssumed Answered

Document Move triggered by Rule.

Question asked by richard.steele@boston.gov.uk on Oct 7, 2015
Latest reply on Oct 13, 2015 by richard.steele@boston.gov.uk
All, I have been using the scripts provided by alfresco to create a set of rules / scripts to archive scanned documents into month folders once a particular criteria has been met.

I have managed to cobble a script to 'copy' the files into the archive - creating it if neccessary. But have not yet been able to sort the syntax to 'move' the document.

The copy code I use is:


// find the backup folder - create if not already exists
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();

var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];


var CurrentDayFolder = "Store -" + monthNames[month]  + " " + year;

var backupFolder = space.childByNamePath(CurrentDayFolder);

if (backupFolder == null && space.hasPermission("CreateChildren"))
{
   // create the folder for the first time
   backupFolder = space.createFolder(CurrentDayFolder);
}
if (backupFolder != null && backupFolder.hasPermission("CreateChildren"))
{
   // copy the doc into the backup folder
   var copy = document.copy(backupFolder);
   if (copy != null)
   {
      // change the name so we know it's a backup
      var backupName = "Backup of " + copy.name;
      copy.name = backupName;
      copy.save();
   }
  
   // record the time of the backup to a log file
   var logFile = backupFolder.childByNamePath("audit.txt");
   if (logFile == null)
   {
      logFile = backupFolder.createFile("backuplog.txt");
   }
   if (logFile != null)
   {
      logFile.content += "File: " + backupName + CurrentDayFolder +
                         "\tDate: " + new Date().toGMTString() +
                         "\tSize: " + copy.size + "\r\n";
   }
}


and tried the foloowing syntax to build the move


var dest = companyhome.childByNamePath("Sites/psn/documentLibrary/test1");
document.move(dest);


can any one suggest a way to join these together as It appears I am not passing the node reference correct.

I am a code newby.

TIA

Richard

Outcomes