cancel
Showing results for 
Search instead for 
Did you mean: 

how to start workflow from javascript service?

rascio
Champ in-the-making
Champ in-the-making
hello,
i'm trying to start a workflow from the javascript service:

        var registrationWorkflowDefinition = workflow.getDefinitionByName("jbpm$" + registrationType);
   
   var parameters = new Object();
   parameters["bpm:workflowDescription"] = getRegistrationLabelForDescription(registrationType) + ' registration for ' + node.name;
   parameters["bpm:assignees"] = [person];
   
   var registrationPackage = packagesFolder.createNode('test', 'bpm:package');
   registrationPackage.addNode(node);
   
   var registrationWorkflowStart = registrationWorkflowDefinition.startWorkflow(parameters, registrationPackage);
but when the code is execute throw the following exception:
Caused by: org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.workflow.jscript.JscriptWorkflowDefinition.startWorkflow(object,org.alfresco.repo.jscript.ScriptNode). (file:/home/manuel/Progetti/ICCROM/alfresco/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/iccrom/registration/startregistration.post.js#23)
   at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
   at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1030)
   at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1086)
   at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:1049)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:162)
   at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)

Anyone can help me?
4 REPLIES 4

rascio
Champ in-the-making
Champ in-the-making
I've solved it….
The documentation is wrong. The method startWorkflow take as first parameter the package and as the second parameter the properties.

jacklovell
Champ in-the-making
Champ in-the-making
I'm also asking the same question. How to start workflow from javascript services? If any one could help me solve my problem? Thanks

vferia15
Champ in-the-making
Champ in-the-making
Hi rascio,

I have checked your code with first parameter the package and as the second parameter the properties and it doesn't work.
Could you please indicate if did you chage any more?

Please, Could you post your code for this web script?

Regards

fufler
Champ in-the-making
Champ in-the-making
I usually use this code to start workflow with JavaScript:
var wfdef = workflow.getDefinitionByName("jbpm$processid");
if (wfdef)
{
   var wfparams = new Array();
   wfparams["bpm:workflowDescription"] = "";
   wfparams["bpm:assignee"] = "admin";
   var wfpackage = workflow.createPackage();
   for each (var fnode in folder.children)
      wfpackage.addNode(fnode);
   var wfpath = wfdef.startWorkflow(wfpackage, wfparams);
   var tasks = wfpath.getTasks();
   for each (task in tasks)
      task.endTask(null);
}