0

I want to implement a loop that will check every object in the list "then" return a boolean value.

function boolean anyActiveUsers(Application app, String params){
    if(app.getApplicantType().toString() == params) {
        for ( User user: app.getUsers()){
            if(user.getStatus() == "ACTIVE")
            return true;
        }

    }
    return false;
 }

But I'm getting an error:  

Function Compilation error anyActiveUsers (line:7): File org/codehaus/groovy/grails/plugins/drools/example/anyActiveUsers.java, Line 15, Column 25: Operator ";" expected

Can someone help me how to implement a for each loop in drools function?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
SpongebobJunior
  • 601
  • 1
  • 9
  • 24
  • You should not take the code from answer and update in the post. It will completely confuse the future readers. – YoungHobbit Jan 12 '16 at 03:20
  • Ok. sorry, but the real issue here is I'm not sure whether the drools supports a for each function or not . – SpongebobJunior Jan 12 '16 at 03:23
  • if it's a java code, what keyword `function` does here? – Igor Artamonov Jan 12 '16 at 03:45
  • This is a drools rule language – SpongebobJunior Jan 12 '16 at 03:50
  • Need Application.java for reproducing the problem. And the Drools version. – laune Jan 12 '16 at 07:19
  • The for statement in a function works fine in 6.3.0 - the error message seems to indicate that you've made some other typo or error. - See my previous comment. – laune Jan 12 '16 at 08:29
  • @IgorArtamonov - `function` is a keyword in the Drools Rules Language (DRL), which essentially lets you write a block of Java code within a DRL file. The rest of that block follows the same rules as a Java method. Therefore, (as you may well have been thinking) testing string equality with `==` is highly unlikely to be appropriate. fwiw - DRL does have its own syntax for writing such tests, as shown in this question: http://stackoverflow.com/questions/22547374/drools-mvel-for-each-element-in-a-map – Steve Jan 12 '16 at 08:55
  • @Steve What Steve (probably) means with the last sentence is that Drools lets you write `==` and `!=` for comparing String values, resulting in a call to `equals` behind the scenes, but *only in rule conditions*. – laune Jan 12 '16 at 11:12
  • Indeed - that is what I meant :) – Steve Jan 12 '16 at 12:28

0 Answers0