Skip to content

Instantly share code, notes, and snippets.

@EvertonSilva
Forked from ejlp12/EA_BPMS_Node_Script.md
Created June 15, 2018 01:39
Show Gist options
  • Save EvertonSilva/5e2679a39c929b582cc5a0d33d3c4089 to your computer and use it in GitHub Desktop.
Save EvertonSilva/5e2679a39c929b582cc5a0d33d3c4089 to your computer and use it in GitHub Desktop.
Jboss bpms, jbpm, brms, script, onexit, onentry

Get and set process variable:

// Set variable
kcontext.setVariable("XYZ", "9000001214"); 

// Get variable
System.out.println("\t##### Process variable XYZ: " + 
                  kcontext.getVariable("XYZ"));
                  
                

On-Exit action example:

System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node");

Vehicle vehicle = (Vehicle)((org.jbpm.workflow.instance.node.WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItem().getParameter("vehicle");
System.out.println(vehicle.getModel());

System.out.println("Actor ID: " + ((org.jbpm.workflow.instance.node.HumanTaskNodeInstance)(kcontext.getNodeInstance())).getWorkItem().getResult("ActorId") );

NOTE: You cannot getWorkItem() in onEntry script, it will result null. Because the WorkItem is not created yet... I guess

Getting output variable names:

HumanTaskNodeInstance nodeInstance = (HumanTaskNodeInstance) kcontext.getNodeInstance();
HumanTaskNode htNode = nodeInstance.getHumanTaskNode();
Map<String,String> outMap = htNode.getOutMappings();

for (Map.Entry<String, String> entry : outMap.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    System.out.println("output task variable "+key+" is mapped to the process variable"+value);

}

Sending event

//kcontext.getKnowledgeRuntime().signalEvent(eventType, data, kcontext.getProcessInstance().getId());

kcontext.getKnowledgeRuntime().signalEvent("TEST_EVENT", null, kcontext.getProcessInstance().getId());

https://access.redhat.com/solutions/1166033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment