cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get all tasks assigned to an user: waiting tasks but not tasks completed in the workflow

geekonspace
Star Contributor
Star Contributor

Hi, I want to know how can I do this: I have a workflow running for each a of my nuxeo documents, this workflow have a WorkflowVariables: transcriber. How can I get all transcribers from workflows of my documents?

Or more easy: How can I get all tasks assigned to an user? open tasks by this user, waiting tasks by this user to be run but not tasks completed

4 REPLIES 4

jmdavid_8121
Champ in-the-making
Champ in-the-making

adam_bo_
Star Contributor
Star Contributor

You can try something like this:

protected CoreSession session = null;

protected List<Task> getAllTasks(NuxeoPrincipal principal) {

	ArrayList<Task> userTasks = new ArrayList<Task>();

	if (session != null) {
        try {
            List<String> actors = TaskActorsHelper.getTaskActors(principal);
        	TaskService taskService = Framework.getService(TaskService.class);
            List<Task> tasks = taskService.getCurrentTaskInstances(actors, session);
            if (tasks != null) {
                for (Task task : tasks) {
                    try {
                        if (task.hasEnded() || task.isCancelled()) {
                            continue;
                        }
                        DocumentModel doc = taskService.getTargetDocumentModel(task, session);
                        if (doc != null) {
                            if (LifeCycleConstants.DELETED_STATE.equals(doc.getCurrentLifeCycleState())) {
                                continue;
                            } else {
                                userTasks.add(task);
                            }
                        } 
                    } catch (Exception e) {
                        //exception handler
                    }
                }
            }
        } catch (Exception e) {
                //exception handler
        }
    }
    return userTasks;
}

Hi, thanks for your answer, but the "taskService.getCurrent TaskInstances(actors, session);" method only gets active tasks and not waiting tasks or ended tasks.

Vinit_Shah
Champ in-the-making
Champ in-the-making

I am not able to access TaskService from my custom java code. What maven dependency I need to include in my core project ? org.nuxeo.ecm.platform.task package is not found.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.