cancel
Showing results for 
Search instead for 
Did you mean: 

How to get taskid in the workflow..

rockycres
Champ in-the-making
Champ in-the-making
Hi,

I need to get taskid for the workflow task (wcmwf:submitReviewTask]..

Can u guys tell me how to get the task id from the workflow service api's or from worlflow execution context…?
7 REPLIES 7

jpotts
World-Class Innovator
World-Class Innovator
Here's a chunk of code from the execute() method of the com.someco.bpm.ExternalReviewNotification class included with the Alfresco Developer Guide book. It is grabbing the node name here with getName() but there is a getId() method as well.


    String recipient = (String) executionContext.getVariable(ExternalReviewNotification.RECIP_PROCESS_VARIABLE);
    StringBuffer sb = new StringBuffer();
    sb.append("You have been assigned to a task named ");
    sb.append(executionContext.getToken().getNode().getName());
    sb.append(". Take the appropriate action by clicking one of the links below:\r\n\r\n");
    List transitionList = executionContext.getNode().getLeavingTransitions();
    for (Iterator it = transitionList.iterator(); it.hasNext(); ) {
        Transition transition = (Transition)it.next();
        sb.append(transition.getName());
        sb.append("\r\n");
        sb.append("http://localhost:8080/alfresco/service/someco/bpm/review?id=jbpm$");
        sb.append(executionContext.getProcessInstance().getId());
        sb.append("-@");
        sb.append("&action=");
        sb.append(transition.getName());
        sb.append("&guest=true");
        sb.append("\r\n\r\n");
    }

Hope that is what you were looking for.

Jeff

rockycres
Champ in-the-making
Champ in-the-making
Hi jeff,

I did tried what u have suggested,but didn't get the exact taskId what I am loooking for .

How can I get the taskId from this executionContext?

processdefiniition.xml
 
 
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wcmwf:submitcustom">

    <swimlane name="initiator"/>

    <start-state name="start">
        <task name="wcmwf:submitReviewTask" swimlane="initiator"/>
        <transition name="" to="validation"/>
    </start-state>

   <task-node name="validation"> 
         <event type="node-enter"> 
                    <script>
                           <variable name="wcmwf_reviewCycle" access="write"/>
                           <variable name="wcmwf_reviewerCnt" access="write"/>
                           <variable name="wcmwf_approveCnt" access="write"/>
                           <variable name="wcmwf_reviewType" access="write"/>
                           <expression>
                             wcmwf_reviewCycle = 1;
                             wcmwf_reviewerCnt = bpm_assignees.size();
                            wcmwf_approveCnt = 0;
                           wcmwf_reviewType = wcmwf_submitReviewType;
                         </expression>
                     </script>
                    <action class="com.sample.action.ValidateActionHandler" name="submit"></action>
         </event>
         <transition name="proceed" to="initialise"/>
     </task-node> 
…..
…..
</process-definition>

ValidateActionHandler.java


public class ValidateActionHandler extends JBPMSpringActionHandler  {
    private WorkflowService workflowService;
    @Override
    protected void initialiseHandler(BeanFactory factory)
   {
           workflowService = (WorkflowService) factory.getBean(ServiceRegistry.WORKFLOW_SERVICE.getLocalName());
   }
   
    public void execute(ExecutionContext executionContext) throws Exception
    {       
        //Inside this method ,I need to get the files submitted to this WF ,so I can get using the taskId like this.
            
      // How can I get the taskId from this executionContext?


               List<NodeRef> contents =workflowService.getPackageContents("jbpm$1");       
            for(int j = 0; j < contents.size(); j++) {
              System.out.println("FILES SUBMITTED "+contents.get(j));   
            }
     
    }
}

jayjayecl
Confirmed Champ
Confirmed Champ
if you are using Eclipse with autom-completion, have a look at executionContext.getInstance() or executionContext.getTask().

There should be some
executionContext.getTask().getId();

or
executionContext.getTaskInstance().getId();

gioele
Champ in-the-making
Champ in-the-making
I'm trying jpotts example, I changed:

executionContext.getProcessInstance().getId()
to
executionContext.getTaskInstance().getId()

but executionContext.getTaskInstance() is null, how come? executionContext.getTask() is also null.

gioele
Champ in-the-making
Champ in-the-making
I found my mistake, in my jPDL file I was calling my code in the event "node-enter", I changed that to the event "task-create" and getTaskInstance() isn't null anymore.

jayjayecl
Confirmed Champ
Confirmed Champ
well done

ruchi3
Champ in-the-making
Champ in-the-making
Hi!

I am also having the similar requirement. Can you please post your complete processdefinition.xml for customized jbpm.

Thanks in Advance.