cancel
Showing results for 
Search instead for 
Did you mean: 

Get workflow from task

mangar
Star Contributor
Star Contributor
2 part question.

I have a Webscript to get all tasks assigned to a user. Works fine.

What I need to know is what workflow it belongs to. I have this code:


     workflowService = registry.getWorkflowService();
     List<WorkflowTask> taskList = workflowService.getAssignedTasks(userId, WorkflowTaskState.IN_PROGRESS);


I iterate through this to make a nice UI list for the user.

How do I get a reference to the workflow itself if I have the taskID and stuff.

Part 2 (related)

I need this info to get values of the workflow model.

How would I get, say, the bpm_workflowPriority value for the workflow of this task?
5 REPLIES 5

yogeshpj
Star Contributor
Star Contributor
You can directly get workflow id from task id .Use following code
String workflowId = task.path.instance.id

mangar
Star Contributor
Star Contributor
Perfect, thank you!

Now how do I get the model data associated with that workflow.  Specifically, I have a custom type in my model.xml file, like "mywf_toName"

How do I get that data?

yogeshpj
Star Contributor
Star Contributor
task.properties will return map which has key as property name and value as property value. Here I am assuming that the property which you want it has been set in task before .

mangar
Star Contributor
Star Contributor
Almost, but not quite.  When I do this:

<java>
Iterator<QName> qit = task.getProperties().keySet().iterator();
</java>

it's not there.  However when I do this at the WorkflowInstance level:
<java>
WorkflowInstance wk = workflowService.getWorkflowById(task.getPath().getInstance().getId());
Iterator<QName> qit =wk.getDefinition().getStartTaskDefinition().getMetadata().getProperties().keySet().iterator();
</java>

I see the QName for it, but I cannot find the way to get the value.

here is my workflow def:

   <process id="privateMessageProcess" name="Private Message Process" isExecutable="true">
      <startEvent id="startevent1" name="Start" activiti:formKey="jiswf:privateMessage"></startEvent>
      <userTask id="usertask1" name="View Private Message" activiti:assignee="${jiswf_toName}">
         <extensionElements>
            <activiti:taskListener event="create" class="org.xxx.alfresco.activity.taskListener.PrivateMessageTaskListener"></activiti:taskListener>
         </extensionElements>
      </userTask>
      <endEvent id="endevent1" name="End"></endEvent>
      <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1">
      </sequenceFlow>
      <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1">
      </sequenceFlow>
   </process>


And in my PrivateMessageTaskListener I get the DelegateTask and that has the prover values, so it's being set correctly. I just need to get it from my webscript.

mangar
Star Contributor
Star Contributor
yogeshPJ Had it right all along.

My mistake was having the activiti:formKey="jiswfSmiley TonguerivateMessage" in the startEvent, not the userTask.

I thought I needed it in the startEvent in order to set the parameters in the workflowService.startWorkflow(),  but I do not. I just added it to the task I was using, the it came out in the task.getProperties() just fine.