cancel
Showing results for 
Search instead for 
Did you mean: 

Completed Worflows by user

mangar
Star Contributor
Star Contributor
I am after a list of WorkflowItem by user. (Who started the workflow)  I can get them by

    workflowService.getCompletedWorkflws();


and then loop through for the getItiator(),  but that seems like that's wrong for very large amount of workflows.

So I try a workflow query like this:


      Map<QName,Object> map = new HashMap<QName,Object>();
      map.put(QName.createQName(AlfrescoModel.BPM_NAMESPACE,"creator"), userId);
      WorkflowInstanceQuery query = new WorkflowInstanceQuery();
      query.setActive(false);
      query.setCustomProps(map);
      List<WorkflowInstance> workflowList = workflowService.getWorkflows(query);


this is always returning 0 workflows.

WHat am I doing wrong?  Is there a good tutorial on the workflow query?  The API documentation is NO help at all.
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
Using

   Map<QName,Object> map = new HashMap<QName,Object>();
   map.put(QName.createQName(AlfrescoModel.BPM_NAMESPACE,"creator"), userId);
   WorkflowInstanceQuery query = new WorkflowInstanceQuery();
   query.setCustomProps(map);

will search workflow instances that have a global variable named {AlfrescoModel.BPM_NAMESPACE}creator and with value userId,it is not what you are looking for.
If you want to search workflow instances that  started  by some one,please do as below

    //First get a person node by user using PersonService.getPerson(String userName)
    NodeRef personNode = personService.getPerson(userId);
    //then define qname initiation search condition
    public static final QName QNAME_INITIATOR = QName.createQName(NamespaceService.DEFAULT_URI, WorkflowConstants.PROP_INITIATOR);
   Map<QName,Object> map = new HashMap<QName,Object>();
   map.put(QNAME_INITIATOR, userId);
   WorkflowInstanceQuery query = new WorkflowInstanceQuery();
   query.setCustomProps(map);
    // search
      query.setActive(false);
      List<WorkflowInstance> workflowList = workflowService.getWorkflows(query);

mangar
Star Contributor
Star Contributor
OK, 2 things,

1.  I believe you mean map.put(QNAME_INITIATOR, personNode);  Because that works!

  2.  I printed out the properties of the workflow and I got this from my log:
Workflow Prop:{http://www.alfresco.org/model/content/1.0}creator Value:userid2

So why did my original query not work?  Is there a difference between a process variable and a global variable?

kaynezhang
World-Class Innovator
World-Class Innovator

Generally, properties setted in customProps will match global variable with same name in  workflow instance.
But QNAME_INITIATOR is a special property ,it will match startBy field.