title: Call BeanShell function from BeanShell Programs like PreProcessor, PostProcessor, Assertion, etc
body: <p><strong>Pre-requisite:</strong>  </p>
  
  <p>Inside JMeter bin folder, I have edited <code>BeanShellFunction.bshrc</code> file to add my function as follows</p>
  
  <pre><code>String getMyString()
  {
      return "MyString";
  }
  </code></pre>
  
  <p>I have enabled the <code>BeanShellFunction.bshrc</code> from <code>jmeter.properties</code> file as</p>
  
  <blockquote>
    <p>beanshell.function.init = BeanShellFunction.bshrc</p>
  </blockquote>
  
  <p>When I use the following syntax to call function it works fine.</p>
  
  <pre><code>${__BeanShell(getMyString())}
  </code></pre>
  
  <p>It works fine for below case:<br>
  <a href="https://i.stack.imgur.com/w8uxZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w8uxZ.png" alt="BeanShell Function Call"></a></p>
  
  <p><strong>Question:</strong> </p>
  
  <p>How can I call the same function from BeanShell Programs like PreProcessor, PostProcessor, Assertion, etc.?</p>
  
  <p><strong>Analysis:</strong>  </p>
  
  <p>I tried with following but no luck:</p>
  
  <pre><code>String myStr = getMyString();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kkh5k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kkh5k.png" alt="BeanShell Assertion"></a></p>
  
  <p>It gives an error as: </p>
  
  <blockquote>
    <p>Assertion error: true<br>
    Assertion failure: false<br>
    Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``  String myStr = getMyString();  print("MyStr: "+myStr);'' : Typed variable declaration : Command not found: getMyString()</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/jj56U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jj56U.png" alt="BeanShell Error"></a></p>