Can you not get a reference to a DetailLine in the LHS?
If you have not inserted DetailLine objects into working memory how can you
expect to retract them?
If you have inserted DetailLine's into working memory what does query "Open
RTV Lines" return, can it be joined into the LHS? (or split into two rules)?
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Ronald R. DiFrango
Sent: 03 October 2007 14:01
To: Rules Users List
Subject: [rules-users] Retract in a function
All,
I have the following function that I call from all of my rules. When I
execute this function, I need to retract that object from working memory.
The problem is that when I insert the comment line below I get a compiler
error saying that I can only issue a retract on fact handles.
Here is an example of my rule plus the function:
rule "QTY Percentage tolerance - Approval"
salience -25
no-loop true
when
rtvHeader : RtvHeader( totalAmount : totalAmount, status not in (
StatusConstants.MATCHED, StatusConstants.APPROVAL) )
repaymentCode : RepaymentCode( code == "QTY", matchApprv ==
"Y",
tolDollar ==0, tolPercent != 0, tolPercent : tolPercent )
qtyOutput : QTYOutput( sumRTVQty : sumRTVQty , sumCmAndRnr :
sumCmAndRnr )
eval( qtyPercentage(qtyOutput, totalAmount, tolPercent) )
then
System.out.println("QTY Percentage tolerance - No Approval");
rtvHeader.setStatus(StatusConstants.APPROVAL );
openRTVLines(drools.getWorkingMemory(),
drools.getWorkingMemory().getQueryResults( "Open RTV Lines" ),
StatusConstants.MATCHED_WITHIN_TOLERANCE);
end
function void openRTVLines(WorkingMemory workingMemory, QueryResults
results, String status)
{
System.out.println( "We have " + results.size() + " Open RTV
Lines" );
for ( Iterator it = results.iterator(); it.hasNext(); ) {
QueryResult result = ( QueryResult ) it.next ();
DetailLine line = ( DetailLine ) result.get( "line" );
line.setStatus(status);
// I need to add this in
// workingMemory.retract(line);
}
}
Thanks in advance,
Ron