Unable to access process variables through rules in Rule Task while using WorkflowProcessInstance

Solution Verified - Updated -

Environment

  • Red Hat JBoss BRMS (BRMS)
    • 5.3.x
  • Red Hat JBoss BPM Suite (BPMS)
    • 6.0.x

Issue

  • While trying to update process variables through rules in Rule Task it is observed that the process variables are not getting accessible, since WorkflowProcessInstance object is not available while rules are trying to fire. How to fix this issue?
  • How to access Process Variables through rules written in DRL or Decision Tables?

Resolution

  • In order to fire the rules to update the process variables from Rule Task , please ensure to insert WorkflowProcessInstance object into Knowledge Runtime [1] before the rule node is fired. One way to do this is to add a Script Task node that executes the following:
kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance());
  • The attached test case AccessProcessVariableInRule.zip is a simple demonstration which has been used around the new KIE API of jBPM6 to execute a BPMN2 process definition to prove that the above functionality to access and update Process Variable from within a rule works. Users from BRMS 5.3.x can take the help of the same process definition attached in the test case for reference purposes as it should work with the old KnowledgeBase API too.

[1] https://community.jboss.org/message/608674#608674

Root Cause

  • Please ensure to insert WorkflowProcessInstance object into Knowledge Runtime before the rule node is fired.

Attachments

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments