cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Candidate group of a given task in activit?

rosir
Champ in-the-making
Champ in-the-making

I am using activiti enterprise and I have synced all groups and users from Keycloak to activiti.. Using the process service editor I have set candidate group for a user task as follows: enter image description here

I have a complete Task method which I am trying to check if the user belongs to the candidate group. I have had a look at the following link

What is the best way to find out the candidate group a task?

and tried taskService.getIdentityLinksForTask(taskId) method and it did not return anything.

What would be the best way to get the candidate group for a task programmatically.

6 REPLIES 6

mdtabrezmca
Star Contributor
Star Contributor

Hi,

  If you are using Tasklistner (DelegateTask task) then you can fetch all the candidate groups using

   task.getCandidates()  which returns  Hashset<IdentityLink>. then you can get the id by looing through it.

Hope it helps.........

rosir
Champ in-the-making
Champ in-the-making

Yes, I can get an Id if I am in TaskListener. but I am looking for something which I can use outside the TaskListener. 

yangfan
Champ in-the-making
Champ in-the-making

In the Activiti API, taskService.getIdentityLinksForTask(taskId) will return the IdentityLinks associated with the given task.

This can do that!

As for you did not return anything, you should check one thing :

In Activiti's tables, the data that exist in act_id_user and act_id_group  must be associated by act_id_membership. Only in this way, the method can return data. Studying these tables is very important.

rosir
Champ in-the-making
Champ in-the-making

All of those tables show empty in mine. I have synced these users and groups from keycloak. Does that make any difference?

yangfan
Champ in-the-making
Champ in-the-making

Oh, the method of Activiti API can only handle the data of 23 tables which generated by Activiti. 

If your users and groups don't exist in Activiti's tables, you should write method by yourself.

Could you show your diagram or xml code?

rosir
Champ in-the-making
Champ in-the-making

I have data in my GROUPS and USERS tables though.

Hi below is the xml code for the User Task:

 <userTask id="sid-7D3D5EEF-F684-4A61-949C-EE40A3DA0F2D" name="Confirm" activiti:candidateGroups="1012" activiti:formKey="22">
<extensionElements>
   <activiti:taskListener event="create" class="com.abc.tasks.listener.MyListener"/>
    <modeler:allow-send-email><![CDATA[false]]></modeler:allow-send-email>
   <modeler:form-reference-id><![CDATA[22]]></modeler:form-reference-id>
   <modeler:form-reference-name><![CDATA[Sys1 - Confirm]]></modeler:form-reference-name>
    <modeler:group-info-name-1012><![CDATA[ABC_ONE]]></modeler:group-info-name-1012>
   <modeler:group-info-externalid-1012><![CDATA[ABC_ONE]]></modeler:group-info-externalid-1012>
   <modeler:activiti-idm-candidate-group><![CDATA[true]]></modeler:activiti-idm-candidate-group>
   <modeler:initiator-can-complete><![CDATA[false]]></modeler:initiator-can-complete>
   <modeler:editor-resource-id><![CDATA[sid-7D3D5EEF-F684-4A61-949C-EE40A3DA0F2D]]></modeler:editor-resource-id>
</extensionElements>
</userTask>