BPM issue #647

Hi,

I am trying to create work flow dynamically that is i will assign the process to the actor on the role basis who is login to the system
and assign the task to all the users with the respective role.

I created process actor(e.g ProcActor) object.

But i am not able to create the process task(e.g ProcTask) object.
Because i am not able to get all the values what process task(e.g ProcTask) object requires that is
i. OUTCOME
2. ACT_EXECUTION_ID
3. NAME
4. ACT_TASK_ID
5. ACT_TASK_DEFINITION_KEY

Here I have attached my code


    @Inject
    private SomeServiceMethod someServiceMethov;
	
    List<ProcActor> procActorList = new ArrayList<ProcActor>();
        
    public void setProcActorsWithUser(List<User> usersWithRole, ProcRole procRole, String processCode){
        for (User user : usersWithRole) {
            ProcActor procActor = metadata.create(ProcActor.class);
            procActor.setProcInstance(procInstance);
            procActor.setUser(user);
            procActor.setProcRole(procRole);
            procActorList.add(procActor);
        }
        ProcDefinition procDefinition = someServiceMethov.getProcDefinition(processCode);
        List<ProcTask> procTaskList = new ArrayList<ProcTask>();
        for(ProcActor procActor : procActorList){
            ProcTask procTask = new ProcTask();
            procTask.setProcInstance(procInstance);
            procTask.setStartDate(new Date());
            procTask.setProcActor(procActor);
            procTask.setName(procDefinition.getModel().getName());
            procTask.setActProcessDefinitionId(procDefinition.getActId());
            procTask.setActExecutionId(procDefinition.getModel().getActModelId());
            procTaskList.add(procTask);
        }
        someServiceMethov.saveProcessActorList(procActorList);
        someServiceMethov.saveProcTaskList(procTaskList);
        
    }

Please suggest me how to fix the issue.

Hi,
you don’t have to create a ProcTask instance in your code. It will be created automatically when the process reaches the UserTask node. In the model, a UserTask node can be associated with some process role. When the process reaches it, ProcTask instances are created for all ProcActors with the given role code.

All you have to do is to create a ProcActor instance, persist it and start the process using the ProcessRuntimeManager.startProcess() method.