cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow API usage

darkredd
Star Contributor
Star Contributor
Good day all,

I am working on a workflow with an escalation requirement. Now I have the logic right, but using the API is somehow eluding me.
I want to run through the "Transitions" of a certain task, but I do not know how or what the keys are stored as in the return map after using the
task.transitions
method.

The following is a snippet of the code I'm working on:

var transactions = {};
      transactions = task.transitions;
      var outcome = "";
                  
      for each (outcome in transactions)
      {
   logger.log("Transitions " + outcome.[reviewOutcome]);
      }


What I would like to know is what are the keys for those transitions in my workflow? I have two possible outcomes: <b>Recommend</b> or <b>Reject</b>.
After all this I have to terminate that certain task.

Thanks in advance.

Regards
9 REPLIES 9

mitpatoliya
Star Collaborator
Star Collaborator
are you using JBPM? Which class you are extending? Please give some more details

Hi mitpatoliya,

I am using Activiti workflow engine. Since the posting of the last question, I have been trying out other ways of getting to end a task to no success. I will show you my code and then explain it subsequently:

Part 1:<javascript>var workDef = workflow.getDefinitionByName("activiti$submissionWorkflow");
        var instance = workDef.getActiveInstances();
   
   for(var workinst in instance)
   {
      var paths = instance[workinst].getPaths();
      
      for(var path in paths)
      {
         logger.log("Instances " + paths[path].getInstance());
      }
   }
</javascript>

Part 2:<javascript>var workDef = workflow.getDefinitionByName("activiti$submissionWorkflow");
var instance = workDef.getActiveInstances();
         
var paths = instance[0].getPaths();
logger.log("Instances " + paths[0].getInstance().getId());</javascript>


Part 3:
 <extensionElements>
    <activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
      &lt;import resource="classpath:alfresco/extension/workflows/scripts/escalation.js"&gt;            
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>


Part 1 of the code does not throw any exception, however; it does not iterate through the arrays. Though I have tested them and found them not to be NULL.

Part 2 gives me an exception saying the methods cannot be found though the API has them:
10:21:18,729 DEBUG [org.alfresco.repo.jscript.RhinoScriptProcessor.calls] string script Exception
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "getPaths" of undefined (AlfrescoJS#21)


Part 3 is where I call the script, with either of part 1 or part 2 code inside it.

Ultimately, once the API is working, I want to end that task using the task.endTask("Approve"); method.

Please have a look and share some insight as to where the problem could be in my code.

Gratitude for the replies and help.

darkredd
Star Contributor
Star Contributor
Hello,

I am using the activiti engine and extending the "ScriptTaskListener" class, here is the snippet:

     <activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>            
         var transactions = {};
         transactions = task.transitions;
         var outcome = "";
           for each (outcome in transactions)
         {
           logger.log("Transitions " + outcome['sita_reviewOutcome']);
         }

                        task.endTask(execution.getVariable('recotaskId'));
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>

As you can see there is an addition to the initial code task.endTask() method which also gives an exception saying "Cannot find function endTask. (AlfrescoJS#85)". Attached as well is the log file.

I hope this will shed some light into my question.

Regards and gratitude

jpfi
Champ in-the-making
Champ in-the-making
hi,
afaik there is no task.endTask() method. The variable task is of type DelegateTask & there is no method end(String transition).
Cheers, Jan

darkredd
Star Contributor
Star Contributor
Hi Jan,

Thanks for the reply,

In accordance with the help documentation and the javascript workflow API documentation, such methods exist.
That said, I followed as well a lot of examples where they used that method with success.
Pardon my dullness, what would your advice be to achieving such a goal (transitioning to the next task)?

Many thanks,

Regards

jpfi
Champ in-the-making
Champ in-the-making
Hi,
pls post your whole process or at least the complete task definition.
I guess you find the usage of endTask following some old jbpm examples?
cheers,
jan

mitpatoliya
Star Collaborator
Star Collaborator
Hi DarkRedd,

I have not tried it in Activiti but yes as you can do the transition by endTask method.

There is one thing you need to do
as a parameter to that method you need to pass the transition id of any one of the possible transitions available from the current task node (From the task node where you have placed that script).

darkredd
Star Contributor
Star Contributor
Hello all,

Let me thank you all for your time in assisting.

To Jan here is the task definition:
<blockcode>    <userTask id="recommendationTask" name="Recommendation Task" activiti:assignee="${recommendationAssignee.properties.userName}" activiti:formKey="sita:recommendationTask">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
               execution.setVariable('sita_reviewOutcome', task.getVariable('sita_reviewOutcome'));
               execution.setVariable('comments', task.getVariable('bpm_comment'));
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
               &lt;import resource="classpath:alfresco/extension/workflows/scripts/variableInitialisation.js"&gt;
               &lt;import resource="classpath:alfresco/extension/workflows/scripts/escalation.js"&gt;
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>            
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="true" activiti:collection="sita_recommenders" activiti:elementVariable="recommendationAssignee">
        <completionCondition>${sita_reviewOutcome == 'Reject'}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask></blockcode>

Please refer to the previous comments for the script.

To mitpatoliya,

I have done as you mentioned. But the method could not be found, even with the parameter specified.

Thank you again

Regards

darkredd
Star Contributor
Star Contributor
Hi all,

We have a found the solution. The JsScriptWorkflowTask.endTask(transitionId) method works. What we did was to get the task by cascading the workflow object to a task level, where we could access the endTask() method.

Thank you for all your replys

Regards