cancel
Showing results for 
Search instead for 
Did you mean: 

[Resolved] Access to Node (documents) from a workflow

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

I would like to access the properties of the documents associated to a workflow. The problem is that I don't know how to retreive the nodes from the ExecutionContext…

The workflow load the java class :

<node name="notifyERP">
      <event type="node-enter">
         <action class="manageoffice.workflows.Demobase" />
      </event>
      <transition to="end1"></transition>
   </node>

The Java class :

public class Demobase implements ActionHandler, configurationModule {
   private static final Logger logger = Logger.getLogger(Demobase.class);
   private BeanFactory factory;
   public Demobase() {
      super();
   }

   @Override
   public void execute(ExecutionContext executionContext) throws Exception {
      if (logger.isDebugEnabled()) {
         logger.info("Will notified ERP Database");
      }
???


How can I get the nodes that where attached at the beginning of the Workflow ?

Thanks Smiley Happy
5 REPLIES 5

jpotts
World-Class Innovator
World-Class Innovator
The nodes that were attached to the workflow are placed in a process variable called "bpm_package". You can iterate over the children of that node from JavaScript written as part of the process definition, or in Java code, which is the route you've chosen.

The code would look something like:

ContextInstance contextInstance = executionContext.getContextInstance();
JBPMNode jbpmNode = (JBPMNode) contextInstance.getVariable("bpm_package"); // there might be a constant that has this somewhere
NodeRef packageNodeRef = jbpmNode.getNodeRef();
List<ChildAssociationRef> childRefList = nodeService.getChildAssocs(packageNodeRef);

for (ChildAssociationRef childAssocRef : childRefList) {
    // do something with each document in the workflow package
    NodeRef nodeRef = childAssocRef.getChildRef()
}

Jeff

dranakan
Champ on-the-rise
Champ on-the-rise
Thank you Jeff Smiley Happy

ivo_costa
Champ in-the-making
Champ in-the-making
Thanks Jeff…

I've been looking to manipulate the Nodes on the workflow too

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

Now I would to do the same with Activiti….
I have done this but I hope there is a better way… I have the workflowId

List<WorkflowPath> paths = workflowService.getWorkflowPaths(workflowId);
         List<NodeRef> nodeAnnexes = new ArrayList<NodeRef>();
         for (WorkflowPath path : paths) {
            List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
            for (WorkflowTask task : tasks){
               List<NodeRef> nodeRefs = workflowService.getPackageContents(task.getId());
               for (NodeRef nodeRef : nodeRefs){
                     boolean ignoreBecauseSame=false;
                     for (NodeRef n : nodeAnnexes){
                        // Avoid to get same document
                        if (n.getStoreRef().equals(nodeRef.getStoreRef())){
                           logger.debug("SAME");
                           ignoreBecauseSame=true;
                           break;
                        }
                     }
                     if (!ignoreBecauseSame){
                        nodeAnnexes.add(nodeRef);
                        logger.debug(nameOfNode);
                        // Can execute actions with the document attached to the workflow…
                        // …
                     }
               }
            }
         }

Could I get all documents more quickly ?

mitpatoliya
Star Collaborator
Star Collaborator
Just curious not much worked with Activii.
What is there in Activii equivalent to the execution context?
Or the same thing is available.
If so then we can use the same code posted earlier I guess.
Or you are trying to access it outside the action class?