I have now tried the following and it did not seem to have the intended result of removing the detail line from working memory:

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);
       
        // Now retract those objects from Working Memory
        FactHandle[] handles = result.getFactHandles();
        System.out.println("handles.length : " + handles.length);
        for(int i = 0; i < handles.length; i++)
        {
            System.out.println("Retracting : ");
            workingMemory.retract(handles[i]);
        }
    }
}

Any other thoughts out there?

On 10/3/07, Ronald R. DiFrango < ron.difrango@gmail.com> wrote:
Michael,

Those detail lines are in working memory for sure.  In fact the query it self only works on working memory objects.

As far as I know you can not place the results of a queryResult in the LHS.

Ron


On 10/3/07, Anstis, Michael (M.) < manstis1@ford.com> wrote:
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@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