cancel
Showing results for 
Search instead for 
Did you mean: 

Modify properties of workflow B while in workflow A

sycha
Champ in-the-making
Champ in-the-making
Hello,

I'd like to set a process variable of a workflow B while in the Java code called in the <event type="node-enter"> of a workflow A.

In other words, I'd like to realise the equivalent to "executionContext.setVariable("varName", value)". But how can I get the equivalent to "executionContext" of workflow B since I am not in the context of workflow B ?

Is it possible ? If yes, how ?

Thank you for your help
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

this is not possible without some major jBPM coding, e.g. using the "low-level" jBPM API in an action handler to gain access to the other process instance via jBPMs process instance management API / services.

Why can't you use the WorkflowService and update task properties with the appropriate method? It is nearly the same as setting a process instance variable, as tasks submit their variables per default into the process instance context. You could define an ever-present system task (assigned to user "System") and have that task transition back to itself right after updating the properties..

Other trail of thought: When these workflows are so inter-related, why are they not distinct, parallel forks within the same process definition or sub-processes (granted, I have not tried working with sub-processes in Alfresco's jBPM engine)?

Regards
Axel Faust

sycha
Champ in-the-making
Champ in-the-making
Hello,

I did it Smiley Happy

Here is the piece of code I used :


import org.alfresco.service.cmr.workflow.WorkflowPath;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.TransientNode;
import org.alfresco.web.bean.workflow.WorkflowUtil;

WorkflowService ws = ServicesUtilsGP.getServiceRegistry().getWorkflowService();

// Create full workflow id (with 'jbpm$' prefix)
String workflowFullId = "jbpm$" + relatedWfId;

// we find the workflow instance
List<WorkflowPath> listeWfPaths = ws.getWorkflowPaths(workflowFullId);
for (WorkflowPath workflowPath : listeWfPaths)
{
   List<WorkflowTask> listWfTasks = ws.getTasksForWorkflowPath(workflowPath.id);
   for (WorkflowTask workflowTask : listWfTasks)
   {
      Map<QName, Serializable> workflowProperties = ws.getPathProperties(workflowPath.id);
      Map<QName, Serializable> taskProperties = workflowTask.properties;
      
      // Here wa can get workflow or task properties
      String wfPropValue = (String) workflowProperties.get(QName.createQName("namespaceUri", "wfPropName"));
      String taskPropValue = (String) taskProperties.get(QName.createQName("namespaceUri", "taskPropName"));
      
      // And set task properties
      // setup a transient node to represent the task we're managing
      WorkflowTaskDefinition taskDef = workflowTask.definition;
      Node taskNode = new TransientNode(taskDef.metadata.getName(), "task_"
            + System.currentTimeMillis(), taskProperties);
      Map<QName, Serializable> properties = WorkflowUtil.prepareTaskParams(taskNode);
      properties.put(QName.createQName("namespaceUri", "taskPropName", "value");

      // execute update
      ws.updateTask(workflowTask.id, properties, null, null);
   }
}