How to execute server-side JavaScript via Alfresco Share

alfrescojavascript

I want to execute some server-side JavaScript (to manipulate repository nodes).

I have admin access via Alfresco Share, but I have no Alfresco Explorer nor SSH access.

  • The best would be a kind of console in which I could type commands, like JavascriptConsole but it can't be installed without SSH access. I don't think there is anything like this, but maybe there are tricks involving rules?
  • Writing one-time webscripts sounds overkill and inconvenient.

Is it possible?
(Alfresco 5.0)

Best Answer

If you don't have any access to the repository machine, I think your easiest option would be the Data Dictionary + dummy rule option

Firstly, create you javascript code on your local machine. Next, upload it into the Data Dictionary. Pick the Repository, then Data Dictionary, then Scripts, so a full path of Repository > Data Dictionary > Scripts. When you upload it, make sure the content / mime type is set to Mimetype: Java Script, changing it in Edit Properties if needed

Now, create a dummy folder somewhere. On that folder, pick Manage Rules, create a new rule. Set it to run on Items are created or enter this folder and perform action of Execute Script and pick your newly uploaded script as the one to run

Finally, create a random file in your folder every time you want to run the script!

Edit: If your script has any problems, then these will only be logged on the repo side, which you won't be able to see. Probably your best bet therefore is to wrap the whole thing in a giant try/catch block, and have it log the exceptions into another file, in a non rules folder!