AnsweredAssumed Answered

Query custom properties

Question asked by sebp on Apr 15, 2010
Latest reply on Apr 2, 2014 by amrorabi
I want to query all workflow tasks that have a cusom property named 'observer' set to the current user name. I tried with:


WorkflowTaskQuery query = new WorkflowTaskQuery();
Map<QName, Object> taskCustomProps = new Hashtable<QName, Object>();
taskCustomProps.put(de.hmedia.alfresco.workflow.WorkflowModel.PROP_OBSERVER, userName);
query.setTaskCustomProps(taskCustomProps);
query.setActive(true);
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
               
// create a list of transient nodes to represent
this.assignedTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
    Node node = createTask(task);
    this.assignedTasks.add(node);
}

But does not return any tasks. I replaced the code above with a query that simply returns all active tasks and then I go through the list of active tasks and check if the property is set. This gives the results I need:


WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(true);
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
               
// create a list of transient nodes to represent
this.assignedTasks = new ArrayList<Node>();
for (WorkflowTask task : tasks)
{
    Map<QName, Serializable> taskCustomProps = task.properties;
    Object o = taskCustomProps.get(de.hmedia.alfresco.workflow.WorkflowModel.PROP_OBSERVER);
    if (o != null && o.toString().equals(userName)) {
        Node node = createTask(task);
        this.assignedTasks.add(node);
    }
}

Why does the task query from the first code example not give the same results? I've checked the hibernate criteria representation of the query. It seems to be ok. The custom 'oberserver' property is contained in the criteria and is mapped correctly. The bpm tables also contain the variable.

Outcomes