cancel
Showing results for 
Search instead for 
Did you mean: 

Business Rule task not updating Java object

mikepoole
Champ in-the-making
Champ in-the-making
I have a business rule task that uses a drl file to update a Java object which was created in a Java Service Task prior to the rule task

I have some printlns in the functions that the drl file triggers so I am confident that the rule task is firing AND evaluating correctly.

The next step in the process is a user task. When I retrieve the values form the Java object to display on the form, they are the pre business task/drools update values

ie:
1. Create Article (my Java object (which implements Serializable)) - set size to 5 and assign Article to process variable "pvArticle"
2. Business Rule task runs and sets size to 50 (Tomcat shows the setSize() method being triggered and this.size being set to 50)
3. User task form has #{pvArticle.getSize()} as the expression - returns 5

What am I doing wrong?

Many thanks

Mike
20 REPLIES 20

johnm
Champ in-the-making
Champ in-the-making
Hi all,

I know this is an old topic, but I'll add my experience here, to help anyone else whom has had the same problem.
I too had this problem, the drool rule was coded to update the obejct passed in, but back in the java code I could
not see the update.

It turns out, (unexpectedly in my mind) that the rule returns a different object reference. Using the api available in the examples to return the object from the rule, inside ruleOutputList is a new reference with the correct updates therein.

<code>
Collection<Object> ruleOutputList = (Collection<Object>) activitiRule.getRuntimeService().
    getVariable(processInstance.getId(),"rulesOutput");
</code>

I had assumed that the instances in the process variable map 'vars' (shown below) would be updated by the rule, and available for my perusal after the rule had run.

<code>
CardApplication cardApp = new CardApplication();
cardApp.setName("Miss Piggy");
  
ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("financialReportWithNoddyRule", vars);
</code>