title: Grails 2.0: Use Service in javascript function in GSP
body: <p>I am just wondering how I can call a method of a service from within a function within a GSP. I tried the following but it does not seem to work:</p>
  
  <pre><code>&lt;%@ page import="com.company.MyService" %&gt;
  &lt;%
      def myService =grailsApplication.classLoader.loadClass('com.company.MyService').newInstance()
  %&gt;
  &lt;html&gt;
  &lt;head&gt;
  [...]
  &lt;script language="javascript"&gt;
      function myFunction() {
  
          if (${myservice.isSomethingAvailable()}) {
             [...]
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I am pretty new to javascript and Grails. Not sure how to achieve that or if it's even possible. Any help appreciated.</p>
  
  <p>Thanks a lot</p>
  
  <p>Jonas</p>