0

I am trying to create a list of companies which appear in either of 2 other lists. I can manage to create a list of companies appearing in 1 other list like this :-

       List masterList = Companies.createCriteria().list(){
            'in'("companyname", alistofcompanies) 
            and {
                or{
                    eq("type","T1")
                    eq("type","T2")
                }                
             order ("companyname")
            }     
        }

But I don't know how to look for companies in either of 2 other lists. I tried this :-

    List masterList = Companies.createCriteria().list(){
            or{
               'in'("companyname", alistofcompanies) 
               'in'("companyname", anotherlistofcompanies)
             }
            and {
                or{
                    eq("type","T1")
                    eq("type","T2")
                }                
             order ("companyname")
            }     
      }

but it gives me a syntax error.

Any clues how I should structure this?

Simon
  • 97
  • 3
  • 13
  • Do you have any error? the code seems correct just need to optimize it. – Nitin Dhomse Aug 24 '18 at 12:08
  • Oh, this is so frustrating. It was giving me a syntax error, but after posting my question here, I guess I must have tidied it up for publishing, its working now! I must have fixed the syntax error without noticing it. – Simon Aug 24 '18 at 15:43

1 Answers1

2

I don't see any syntax issue except you can improve the code and it is working.

 List masterList = Companies.createCriteria().list() {
            'in'("companyname", alistofcompanies + anotherlistofcompanies)
            'in'("type", ["T1", "T2"])
             order("companyname")
  }
Shivam Pandey
  • 3,756
  • 2
  • 19
  • 26