Dynamic assignment of user task [clarification]

Hi guys,
I got my own user assignment using dmn engine based on entity properties. Output of my service is list of users which should be assigned to user task. But standard activiti Assignment (assignee, candidate users) doesnt work, if you insert UUID into Assignment-> assignee, it throws

cuba BpmException: ProcRole code for task sid-xxxxxxxxxxxxxx not defined

[even if I added proc role to user task and set its value during start process]
If you insert UUID into Assignment -> candidate users, it will start process, but will ignore this values.
Without this you cant dynamically set users to task.

Use case: You have generated list of users for which you need to run approval task (approve/reject/reassign/clarification) and you want to end all tasks with reject outcome if eg. 1 of all, 50% reject, 2 of all reject or end all task with accept outcome if eg. 70% accept, at least 3 approve, etc. [Schema sub-process which get collection of users, element variable is user, and you assign this user to UserTask inside and you set sub-process completion something like ${no_approvals >3 || no_rejects > 0}]
Is this somehow achievable? - ignore/turn off proc roles and use standard Assignment ? I tried all I could, but there is not much info about this in BPM addon doc.
Thank you for any help/clarification.

Point no.2: In ProcessRuntimeManagerBean -> method createProcTask you take assignee from TaskEntity, if there is anything in UserTask Assignment->assignee, this value is taken from here [this is processed by activiti engine] and you are retrieving procActor based on this value

ProcActor procActor = findProcActor(bpmProcInstanceId, roleCode, UUID.fromString(assignee));

while this wont match as you are not creating ProcActors based on Assignment->assignee and it will fail with

"ProcActor " + roleCode + " not defined"

You can achieve usage of Assignment->assignment of user task based on UUID. (Described solution is for 1 UUID not for multi instance, as I like to handle multiple instances using sub-process for better control as described in first comment, until v6.6 you can make sub-process working as described here https://www.cuba-platform.com/discuss/t/wrong-implementation-of-bpm-evaluator-according-to-subprocesses )

  1. Create procRoles in your model (no matter how many and where you assign them), every user task have to have Proc Role defined.
  2. override ProcessRuntimeManagerBean in core package
import com.google.common.base.Strings;
import com.haulmont.bpm.core.ProcessRuntimeManagerBean;
import com.haulmont.bpm.entity.ProcActor;
import com.haulmont.bpm.entity.ProcInstance;
import com.haulmont.bpm.entity.ProcTask;
import com.haulmont.bpm.exception.BpmException;
import com.haulmont.cuba.core.EntityManager;
import com.haulmont.cuba.security.entity.User;
import org.activiti.engine.impl.persistence.entity.TaskEntity;

import java.util.UUID;

public class MyCustomProcessRuntimeManagerBean extends ProcessRuntimeManagerBean {
    @Override
    public ProcTask createProcTask(TaskEntity actTask) {
        String assignee = actTask.getAssignee();
        if (Strings.isNullOrEmpty(assignee))
            throw new BpmException("No assignee defined for task " + actTask.getTaskDefinitionKey() + " with id = " + actTask.getId());

        UUID bpmProcInstanceId = (UUID) actTask.getVariable("bpmProcInstanceId");
        if (bpmProcInstanceId == null)
            throw new BpmException("No 'bpmProcInstanceId' process variable defined for activiti process " + actTask.getProcessInstanceId());
        EntityManager em = persistence.getEntityManager();

        ProcInstance procInstance = em.find(ProcInstance.class, bpmProcInstanceId);
        if (procInstance == null)
            throw new BpmException("Process instance with id " + bpmProcInstanceId + " not found");

        String roleCode = extensionElementsManager.getTaskProcRole(actTask.getProcessDefinitionId(), actTask.getTaskDefinitionKey());
        if (Strings.isNullOrEmpty(roleCode))
            throw new BpmException("ProcRole code for task " + actTask.getTaskDefinitionKey() + " not defined");
        ProcActor procActor = findProcActor(bpmProcInstanceId, roleCode, UUID.fromString(assignee));
        if (procActor == null) //Create procActor for this task role based on Assignment->assignment UUID
        {
            User assigneeUser = em.find(User.class, UUID.fromString(actTask.getAssignee()));
            if(assigneeUser == null)
                throw new BpmException("Assignee defined for task " + actTask.getTaskDefinitionKey() + " doesn't exist");
            procActor = (ProcActor)this.metadata.create(ProcActor.class);
            procActor.setProcInstance(procInstance);
            procActor.setProcRole(this.findProcRole(roleCode));
            procActor.setUser(assigneeUser);
            em.persist(procActor);
        }
        return super.createProcTask(actTask);
    }
}
  1. add this line to spring.xml in core package
<bean id="bpm_ProcessRuntimeManager" class="your.package.MyCustomProcessRuntimeManagerBean"/>