cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a workflow from the web script?[Solved]

efycaci_ramesh
Champ in-the-making
Champ in-the-making
I have a requirement to call an Alfresco workflow from webscript and calling a webscript within workflow.

Can anyone have the example for these scenarios?

Thanks in advance.
1 REPLY 1

zladuric
Champ on-the-rise
Champ on-the-rise
Well, here is one way to do it.

If I want to start a new workflow from javascript (webscript controler script):
   var assignee = site.assocs["custom:AssigneePerson"][0]; // This could also be username literal, ie assignee = "admin"
      var doc = site.childByNamePath("documentLibrary/path/to/filename.txt");
      var date = new Date();
      var workflow = actions.create("start-workflow");
      workflow.parameters.workflowName = "jbpm$workflowModelNamespace:workflowName"; // the part after jbpm$ is found in your workflow definition/workflow model.
      workflow.parameters["bpm:workflowDescription"] = "Something to distinct this workflow by in the My Tasks list";
      workflow.parameters["bpm:assignee"] = assignee;
      workflow.parameters["bpm:dueDate"] = date;
      workflow.execute(doc);

That's how I start the workflows.

And calling a webscript from a workflow?

Well, not sure about that. I just add a bit of javascript in the workflow to call it, ie:
      <transition to="end" name="SomeTaskNode">
                  <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                  // I put my javascript code to do whatever.
               </script>
               </action>
      </transition>

Now, I don't know how to call webscripts from alfresco. I don't know how to call any URL from alfresco javascript, while we're at it Smiley Tongue