Hi, I have two objects in my domain. Customer and Item objects. Each item has a unique item code. The goal is to group item objects based on the item code. So, as soon as I receive an item from a customer, I run my rule to find out 2 things: 1) If the customer already has an item with the same item code. If so, I just update the item with the new quantity 2) If customer does not have the item type, I create a new item of that type under that customer object.
To differentiate between the incoming item and the one that is already grouped, I have a IncomingItem and GroupedItem object type. Customer contains a list of grouped items. Customer, groupedItems and incomingItems are a part of my working memory. I compare incoming Item against the grouped Item of customer to determine what i need to do. Following are the two rules that does that for me: rule "Item Exist" salience 100 when incomingItem : IncomingItem() customer : Customer( $groupedItems: groupedItems -> ($groupedItems.containsKey(incomingItem.item))) then customer.updatedGroupedItem(incomingItem); end rule "Item Does Not Exist" salience 90 when incomingItem: IncomingItem() customer : Customer( $groupedItems: groupedItems -> ($groupedItems.containsKey(incomingItem.item) == false)) then System.out.println("Executing No Matched Grouped Items Rule"); customer.addGroupedItem(new GroupedItem(...)); end I tried the following steps: 1. I created a customer test object with two dummy grouped item objects with unique item code ( item1 and item2). 2. I created two dummy incoming item objects with item code as 'item3'. 3. I populated my working memory with my customer, grouped item and incoming objects and fired the rule. I was expecting the following to happen: Since 'item3' is not already present for this customer, the 'Item does not exist' rule condition would get satisfied. My understanding so far was right. A new groupeditem object of type 'item3' was created and added to the customer. Now, there was one more incoming item of the same type in the working memory. I was expecting the 'item exist' rule to be executed. Because, the groupeditem just got created as a result of the first object. But, that is not the case. The 'Item does not exist' rule gets executed again. Do I need to call modifyObject on my customer or something for the next item object to correctly identify that a item of that type already exist for that customer? Is this the right way to go about this peice of requirement. Thanks in advance. -- View this message in context: http://www.nabble.com/Question-on-working-memory-and-its-working-tf2899258.html#a8100179 Sent from the drools - user mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email