cancel
Showing results for 
Search instead for 
Did you mean: 

Query custom properties

sebp
Champ in-the-making
Champ in-the-making
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.
3 REPLIES 3

hsohaib
Champ on-the-rise
Champ on-the-rise
try this code :


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.equals(userName)) {
        Node node = createTask(task);
        this.assignedTasks.add(node);
    }
}

And see if it returns any results, if no results are returned that means the value of PROP_OBSERVER is not a String, which means you shouldn't pass the userName as String, but as the appropriate class in :


taskCustomProps.put(de.hmedia.alfresco.workflow.WorkflowModel.PROP_OBSERVER, userName);

sebp
Champ in-the-making
Champ in-the-making
Thanks for the answer. I tried and the property is string.

amrorabi
Champ in-the-making
Champ in-the-making
Hello, anybody solved this problem ?!
Getting started

Tags


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.