11-17-2015 05:35 AM
11-18-2015 05:15 AM
02-18-2019 05:07 AM
Since this is one of the first hits when searching for a solution to this problem, I'll add another answer.
I found the approach of building a generic content stream webscript (described in this post on ServerFault) very convenient. In Data Dictionary/Web Script Extensions create a folder for your webscript, e.g. under it/myorganization/jsrunner, and in this folder create a descriptor, e.g. jsrunner.get.desc.xml, with the following content:
<webscript kind="org.alfresco.repository.content.stream">
<shortname>Run script</shortname>
<description>Webscript to execute a repository script</description>
<url>/jsrun</url>
<format default="">extension</format>
<family>myorganization</family>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
Then create jsrunner.get.js:
// in this example we write the log directly in Company Home, YMMV
var log_node = companyhome.childByNamePath('jsrunner.log') ;
companyhome.removeNode(log_node) ;
var log_node= companyhome.createNode('jsrunner.log', 'cm:content') ;
var log_text = '' ;
// your code goes here, append to log_text some useful messages
log_node.content = log_text ;
model.contentNode = log_node ;
You need to refresh the webscripts once (from /alfresco/s/index), then you can change the js code and execute it again with no need to refresh. I had no need to add parameters to the webscript, but that is also quite straightforward. I think this approach is more flexible than the old execute command servlet.