[rules-users] Is it possible to Iteriate over a list of string values ?

FrankVhh frank.vanhoenshoven at agserv.eu
Wed Mar 9 03:41:33 EST 2011


Hi all,

The way I understand your question, you want to evaluate some string value
to a list of Strings, and insert an "alarm" in the form of a new object to
notify that these values are present.

This is possible. Insert a String into working memory, then call the
following rule: 

#Testing rule
rule "test"
	when
		$vals: String(this in ("help","support","assist"))
                not Fact(value == $vals )
	then
                insert ( new Fact ( $vals ) );
		System.out.println("This WORKS!");
end

The rule checks for a String in working memory, and evaluates its contents (
this in ( list ) ) . If a Fact with the corresponding value hasn"t been
inserted yet, it will be inserted at runtime.

Regards,
Frank


groovenarula wrote:
> 
> Hello all,
> 
> In one of my use cases, I need to insert a variable collections of facts
> into working memory in order to be able to test for those values later :
> 
> So I was wondering if there's a way to do something like this 
> 
>     when
>         $vals : String() from [ "A 12345", "B 45678", "C 8695" ]
>     then
>          insert ( new Fact ( $vals ) );
> 
> With the intention that the rule will fire 3 times and insert the 3 new
> facts with the values " A 12345" and "B 45678" and "C 8695".
> 
> Is this possible using rules or do I have to resort to using functions.
> The problem I'm trying to overcome is to see if there's a way to get the 
> "A 12345", "B 45678", "C 8695"  from a single cell of a spreadsheet.
> 
> Thanks in advance,
> G
> 


--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Is-it-possible-to-Iteriate-over-a-list-of-string-values-tp2654135p2654347.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list