title: How can I put an if statement inside of a createCriteria in grails?
body: <p>I'm new in grails and I have a problem. I have a method that receive some data and match the data with a createCriteria and return the data. It's working fine, but that I want to do now if match with the five params that I have in the method and if match return the data, if not match with the five params, try if match with four params and return the data, if not match with the four params, try if match with three and return the data....</p>
  
  <p>But not really sure how can I put all this in a if statement and return my result.dataPerson or maybe I have to find another way to do it.</p>
  
  <p>My method:</p>
  
  <pre><code>def getPersonData(String name, String surname, String address, String phone){
  
  
      def searchdataPerson = ClientConfig.createCriteria()
      def result = searchdataPerson.get{
          and{
              or{
                  eq('surname', surname)
                  isNull('surname')
              }
              or{
                  eq('address', address)
                  isNull('address')
              }
              or{
                  eq('phone', phone)
                  isNull('phone')
              }
              or{
                  eq('name', name)
                  isNull('name')
              }
          }
          maxResults(1)
      }
  
      return result.dataPerson
  }
  </code></pre>
  
  <p>I'm trying to do something like this but it doesn't work</p>
  
  <pre><code>def searchdataPerson = ClientConfig.createCriteria()
          def result = searchdataPerson .get{
              if(eq('name', name) &amp;&amp; eq('surname', surname) &amp;&amp; eq('address', address) &amp;&amp; eq('phone', phone)){
              }else if(eq('name', name) &amp;&amp; eq('surname', surname) &amp;&amp; eq('address', address)){
              }       
              maxResults(1)
          }
  return result.dataPerson
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>java.lang.NullPointerException: Cannot get property 'dataPerson' on null object
  </code></pre>