Check if a List <String> field contains any of the comma separated values

4,797 views
Skip to first unread message

AV

unread,
Nov 7, 2017, 10:46:45 AM11/7/17
to Drools Usage
Hey folks,

I have a scenario (as described below) where I need to check if a list contains any one of the values but I am trying to figure out a way to pass it as comma separated values.

Scenario:

We have a field called code which was of type String, and say the rule requirement is - If code is Code1 or Code2 or Code3, then perform some actions.

We were able check for all the three codes - Code1, Code2 and Code3 in a same row in a decision table or in a guided rule too by putting comma separated values.

Now, as per the new requirement we can have multiple codes in the request and hence we had to change the data type of code to List<String>;

Issue:

To check for each code, I have to put a new row in a guided decision table or an OR condition in a guided rule like 

code contains Code1 
or code contains Code2 
or code contains Code3

which earlier I was able to put as,

code is contained in the (comma separated) list Code1, Code2, Code3.


Is there a way to check if the code (which is a List<String> now) contains any of the comma separated values?


Thanks,
AV

Adarsh22X22Singh

unread,
Nov 7, 2017, 12:46:28 PM11/7/17
to Drools Usage
Good Question.

AV

unread,
Nov 9, 2017, 10:42:52 AM11/9/17
to Drools Usage
Any ideas / suggestions?

Thanks,
AV

Michael Anstis

unread,
Nov 9, 2017, 10:57:00 AM11/9/17
to Drools Usage
In DRL terms you should be able to do something like:

YourFact( $codes : codes )
String( this in ("code1", "code2" ) ) from $codes

This can be created with both the Guided Rule Editor and Guided Decision Table Editor (using Free From Lines)

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/e171302c-cf84-4b2c-aebc-6b5feceffcf9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ramesh C

unread,
Nov 13, 2017, 10:12:35 AM11/13/17
to Drools Usage
Hi, 

 you can use matches with regular expression to find with for key word combination to iterate list of string.

Regards
Ramesh

AV

unread,
Nov 14, 2017, 2:43:35 PM11/14/17
to Drools Usage
Yes but I wanted to avoid using any DRL/Code in the table for this field. Would be more readable to business users if I just had comma separated values in a cell and it looked if any of the comma separated values exist in the collection its checked against.

Thanks,
AV


On Thursday, November 9, 2017 at 10:57:00 AM UTC-5, Michael Anstis wrote:
In DRL terms you should be able to do something like:

YourFact( $codes : codes )
String( this in ("code1", "code2" ) ) from $codes

This can be created with both the Guided Rule Editor and Guided Decision Table Editor (using Free From Lines)
On 9 November 2017 at 15:42, AV <brinji...@gmail.com> wrote:
Any ideas / suggestions?

Thanks,
AV

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

AV

unread,
Nov 14, 2017, 2:45:28 PM11/14/17
to Drools Usage
Can you put an example on how the data would look like in the decision table.

Would appreciate if you can share some more info on this like a tutorial etc. in case you have/find a link for the same.

Thanks,
AV
Reply all
Reply to author
Forward
0 new messages