cancel
Showing results for 
Search instead for 
Did you mean: 

execute a self defined java script

aditya
Champ in-the-making
Champ in-the-making
Hi,

I am using alfresco 1.4RC and mysql as database. I wish to execute a java script file with the help of content rules. I copied an exisiting js file (backup.js) located in
Company Home >> Data Dictionary >> Scripts

and copied it back after renaming it. Then I created a content rule to execute this newly added java script to be applied on an inbound file.

When I try adding a new content to the space it gives me following error

  Please correct the errors below then click OK.
A system error happened during the operation: Transaction didn't commit: Failed to execute script 'workspace://SpacesStore/fa9bba8e-6988-11db-8dcc-939f14851605': illegal character (AlfrescoScript#1)


and the file was not added to the space.

Can someone please suggest where am i going wrong.

Thanks
Aditya Malpani
3 REPLIES 3

kevinr
Star Contributor
Star Contributor
Can you post the contents of the modified file?

aditya
Champ in-the-making
Champ in-the-making
Hi Kevin,

I did not modify the file backup and log.js, I just renamed the file as backup and log_copy.js and added it to the scripts folder. Then i tried executing both the files using a content rule applied on an inbound file (seperately). The rule involving backup and log.js worked fine but one with backup and log_copy.js gave the error.

Actually i wish to start a complex workflow programatically, for this i am invoking the content rule. But i am not sure whether my script file was correct so i used the one of the predefined  files for testing, just to make sure that the script file was properly defined.

following is the code from the backup and log_copy.js

// find the backup folder - create if not already exists
var backupFolder = space.childByNamePath("Backup_temp");
if (backupFolder == null && space.hasPermission("CreateChildren"))
{
   // create the folder for the first time
   backupFolder = space.createFolder("Backup_temp");
}
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("backuplog.txt");
   if (logFile == null)
   {
      logFile = backupFolder.createFile("backuplog.txt");
   }
   if (logFile != null)
   {
      logFile.content += "File: " + backupName +
                         "\tDate: " + new Date().toGMTString() +
                         "\tSize: " + copy.size + "\r\n";
   }
}

Regards,
Aditya Malpani.

kevinr
Star Contributor
Star Contributor
I've just tried to duplicate your issue, I tried copy-and-paste of "backup and log" script, and also tried directly pasting in the code you posted. Both of them worked fine.

Can you try this again, it's a very strange error you're getting from the script engine, as 'illegal character (AlfrescoScript#1)' suggests there is a problem with the script on the first line, e.g. a strange character…

Thanks,

Kevin