Hi Denis,
Giving a setter for scriptService worked. but now when i execute the script i get the following error:
18:05:57,359 INFO [repo.mytest.RhinoScriptTest] invokeScript
18:05:58,109 INFO [repo.mytest.RhinoScriptTest] after createNode
18:05:58,125 INFO [repo.mytest.RhinoScriptTest] Before executescript
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'o
rg/alfresco/repo/mytest/workflow.js': Can't find method org.alfresco.repo.jscrip
t.ScriptAction.execute(org.mozilla.javascript.Undefined). (AlfrescoScript#3) at org.alfresco.repo.jscript.RhinoScriptService.executeScript(RhinoScrip
tService.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
……………….
My class for your ref:
public void invokeScript()
{
logger.info("invokeScript");
StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "rhino_" + System.currentTimeMillis());
NodeRef root = nodeService.getRootNode(store);
try
{
ChildAssociationRef childRef = nodeService.createNode(
root,
BaseNodeServiceTest.ASSOC_TYPE_QNAME_TEST_CHILDREN,
QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "script_content"),
ContentModel.TYPE_CONTENT,
null);
logger.info("after createNode");
TemplateNode concept
Map<String, Object> model = new HashMap<String, Object>();
model.put("doc", new Node(childRef.getChildRef(), serviceRegistry, null));
model.put("root", new Node(root, serviceRegistry, null));
logger.info("Before executescript");
Object result = scriptService.executeScript(TESTSCRIPT_CLASSPATH2, model);
System.out.println("Result from TESTSCRIPT_CLASSPATH2: " + result.toString());
}
catch (Throwable err)
{
err.printStackTrace();
}
}
private static final String TESTSCRIPT_CLASSPATH2 = "org/alfresco/repo/mytest/workflow.js";
I even packaged the class org.alfresco.repo.jscrip
t.ScriptAction along with my class. But it says 'cannot find method ', though the method is there.
I also dont know how to pass the parameters to my script. As my script is to execute workflow, i need to pass the current document reference.
I altered the container.jsp to add a button and call my action:
<tr>
<td align="center">
<h:commandButton id="workflow-button" styleClass="wizardButton"
value="Start Workflow"
action="#{testService.invokeScript}"
disabled="#{WizardManager.finishButtonDisabled}" />
</td>
</tr>
Pls help out.