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

cancel
Showing results for 
Search instead for 
Did you mean: 
rosir
Member II

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

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
mdtabrezmca
Established Member II

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

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.........

yangfan
Member II

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

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
Member II

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

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

rosir
Member II

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

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
Member II

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

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
Member II

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

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>