---
title: "Groovy script tester in JMCF"
canonical: "https://support.appfire.com/space/JMCF/465764674/Groovy%20script%20tester%20in%20JMCF"
format: markdown
---
> Macro (aura-html)

### **Groovy script tester availability**

<span style="color: #091e42">The Groovy script editor in JMCF is available on the Custom field configuration screens of calculated custom field types that expect the result of a </span>`Groovy script.`

### **Using the Groovy Script tester**

<span style="color: #000000">After </span>[<span style="color: #000000">writing your Groovy script</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465305771)<span style="color: #000000"> in the </span>[<span style="color: #000000">editor</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465600948)<span style="color: #000000">, click on the </span>`Test Groovy Script `button on the toolbar`.`` `<span style="color: #000000">A modal dialog window opens, asking you to pick an issue to run the Groovy script against, as well as a linked issue, where applicable. </span>

#### **Selecting an issue**

<span style="color: #000000">You can select the issue from one of the following options:</span>

- **<span style="color: #000000">Issue key:</span>**<span style="color: #000000"> start typing an </span>*<span style="color: #000000">issue key</span>*<span style="color: #000000">, you will be offered options based on your issue browsing history</span>
- **[Select issue]**<span style="color: #000000">: if you click on </span>`[Select Issue]`,<span style="color: #000000"> an Issue selector window gets displayed. You can select the issue either from:</span>
  - **<span style="color: #000000">Recent Issues</span>**<span style="color: #000000">: Displays issues that you have recently viewed and first 50 issues from your current search or</span>
  - **<span style="color: #000000">From Filter</span>**<span style="color: #000000">: Displays issues of your saved searches.</span>

<span style="color: #000000">The </span>[<span style="color: #000000">issue</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465732169/Variables+and+functions+used+in+a+Groovy+script#issue)` `<span style="color: #000000">variable used in your script will point to the above-selected issue. </span>

#### **<span style="color: #000000">Testing your Groovy script</span>**

<span style="color: #000000">After selecting issue against which the script should be tested (as explained </span>[<span style="color: #000000">above</span>](#GroovyscripttesterinJMCF-Selectinganissue)<span style="color: #000000">), click on </span>`Test. `<span style="color: #000000">The following information will be displayed. This information can be used for </span>[<span style="color: #000000">debugging</span>](#GroovyscripttesterinJMCF-Debuggingyourscript)<span style="color: #000000">.</span>

1. **<span style="color: #000000">Message</span>**<span style="color: #000000">: Success/error message based on the test result.</span>
2. **<span style="color: #000000">Result type</span>**<span style="color: #000000">: Data type of the result.</span>
3. **<span style="color: #000000">Result value</span>**<span style="color: #000000">: Value of the result.</span>
4. **<span style="color: #000000">Stack:</span>**<span style="color: #000000"> If an exception was thrown during the execution of the script, a stack trace will be displayed.</span>
5. **<span style="color: #000000">Logs</span>**<span style="color: #000000">: Information logged using the </span>[<span style="color: #000000">log</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465732169/Variables+and+functions+used+in+a+Groovy+script#log)<span style="color: #000000"> variable.</span>

<span style="color: #000000">**Example**</span>

> ℹ️ *<span style="color: #000000">Test a script that returns the sum of two number fields:</span>*
> ℹ️ 
> ℹ️ 1. Locate the custom field <span style="color: #333333">on the Custom Fields administration page.</span>
> ℹ️ 2. Click on the cog wheel and click <span style="color: #333333">on </span>`Configure.`
> ℹ️ 3. Click on` Edit Groovy Formula`
> ℹ️ 4. In the [Groovy editor](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465600948),<span style="color: #000000"> write the following lines of code:</span>
> ℹ️ 5. Click on the `Test Groovy Script `button on the toolbar.
> ℹ️ 6. Type an Issue key.
> ℹ️ 7. Click on `Test.`
> ℹ️ 8. The following result is displayed:
> ℹ️ 9. > Macro (inline-media-image)

#### <span style="color: #000000">Debugging your script</span>

<span style="color: #000000">If you encounter an error during testing, you will need to debug your script. The </span>[<span style="color: #000000">Message, Stack and Log</span>](#GroovyscripttesterinJMCF-TestingyourGroovyscript)<span style="color: #000000"> information displayed in the script test</span><span style="color: #000000">er result panel aids in debugging the script.</span>

##### <span style="color: #000000">**Using the Message and Stack trace**</span>

<span style="color: #000000">In the above example, </span><span style="color: #000000">after encountering the error, </span>

- **<span style="color: #000000">Identify the problem,</span>**<span style="color: #000000"> from the </span>`Message`<span style="color: #000000"> that displayed a null pointer exception error and the </span>`Stack`<span style="color: #000000"> that displayed the line number on which the error occurred.</span>
- **<span style="color: #000000">Correct the problem,</span>**<span style="color: #000000"> </span><span style="color: #000000">c</span><span style="color: #000000">hecking for null values and then returning the result.</span>
  - In the [Groovy editor](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465600948),<span style="color: #000000"> write the following lines of code:</span>
  - Click on `Test again`.
  - The following result is displayed:  
> Macro (inline-media-image)

##### <span style="color: #000000">**Using the log variable**</span>

<span style="color: #000000">Using the log variable, you can debug your script, a step further, by adding information into the log. For example, while testing a condition in your script, if the result evaluates to </span>`false `<span style="color: #000000">when you expect it to be </span>`true`<span style="color: #000000">, you might want to know what values are being compared in your condition. In such cases, you can use the log variable to display the value.</span>

> ⚠️ The log calls should always be used before the return statement because they would never get executed *after *it.

- **<span style="color: #000000">Use log variable</span>**<span style="color: #000000">, in the above script to know the values of the custom fields.</span>
- **Re-test the script**, the following result is displayed.
- > Macro (inline-media-image)
- <span style="color: #000000">**Remove your logging code**</span><span style="color: #000000">, so that log entries don't get written to Jira's logfile each time the field is calculated.</span>