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

### <span style="color: #000000">**Groovy script tester availability**</span>

The Groovy script tester in JMWE is available on the:

- The Groovy script editor in JMWE is available on the:
  - Post-function configuration screen when you select:
    - Groovy expression/Groovy Template as *Value type* in the post-functions that set a field value
    - Groovy expression/Groovy Template as *Comment type* in the post-functions that comment an issue
    - the [Conditional execution](https://appfire.atlassian.net/wiki/display/JMWE/Conditional+execution+using+Groovy+expression) option in any post-function
  - Post-function configuration screen of the [Create/Clone issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78054650) post-function when you select:
    - Calculated as *Project*
    - Calculated as *Parent issue*
    - Set field value from Groovy or Set field value from Groovy template while setting a field in *Set fields of new issue*
    - Groovy expression/Groovy Template as *Comment type* while adding a comment to the current issue
  - Target issues section of all post-functions that operate on related issues when Issues returned by a Groovy script or Issues returned by JQL search is selected under Which Issues field.
  - Post-function configuration screen of the [Email issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78056800) post-function while writing the Email content and recipients
  - Post-function configuration screen of the [Link issues to the current issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78056808) post-function while writing the JQL search expression
  - Post-function configuration screen of the [Unlink issues from the current issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78056790) post-function
  - Configuration screens of the [Scripted (Groovy) condition](https://appfire.atlassian.net/wiki/display/JMWE/Scripted+%28Groovy%29+condition), [Scripted (Groovy) validator](https://appfire.atlassian.net/wiki/display/JMWE/Scripted+%28Groovy%29+validator) and [Scripted (Groovy) operation on issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78057485) post-function
  - [<span style="color: #000000">Groovy Console</span>](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78053885) admin screen that allows you to test/run Groovy scripts
  - [Shared Groovy Scripts](https://appfire.atlassian.net/wiki/x/xAynB) under JMWE administration

### <span style="color: #000000">**Using the Groovy Script tester**</span>

After [writing your Groovy script](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78055704) in the [editor](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78054281), click on the Test Groovy Script button on the toolbar. A modal dialog window opens, asking you to pick an issue to run the Groovy script against, as well as a related issue, wherever applicable. 

#### <span style="color: #000000">**Selecting an issue**</span>

<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>
- <span style="color: #000000">**[Select issue]**</span><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/JMWE/pages/461799437/Groovy+Variables+and+Functions#issue)` `<span style="color: #000000">variable used in your script will point to the above-selected issue. </span>

#### **<span style="color: #000000">Selecting a related issue</span>**  


In post-functions that process an issue’s related issues, after you select an issue (as explained above) in the tester, all issues related to it through the relation selected in Which issue(s) are displayed under `Linked issue key`. The `relatedIssue` variable and the deprecated `linkedIssue` variable used in your script will point to the selected related issue. For example: If the relation is the issues returned by the JQL search, the tester `Linked issue key` field will show issues that are a result of the JQL search.

In the post-functions that process the parent issue, after you select an issue (as explained above), its parent is displayed under `Parent issue key`. The `parentIssue` variable used in your script will point to the parent issue you select.

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

<span style="color: #000000">After selecting issue(s) against which the script should be tested (as explained above), 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>](#GroovyscripttesterinJMWE-Debuggingusingthescripttester)<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/JMWE/pages/461799437/Groovy+Variables+and+Functions#lo)<span style="color: #000000"> variable.</span>

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

> ℹ️ *<span style="color: #000000">Test a script that fetches the username of the user the issue is assigned to:</span>*
> ℹ️ 
> ℹ️ 1. <span style="color: #000000">Add the </span>[<span style="color: #000000">Set field value</span>](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461767530)<span style="color: #000000"> post-function to a transition. </span>
> ℹ️ 2. Select<span style="color: #000000"> </span>`Groovy expression` as the *Value type*.
> ℹ️ 3. In the [Groovy editor](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461897846),<span style="color: #000000"> write the following lines of code:</span>
> ℹ️ 4. Click on the `Test Groovy Script `button on the toolbar.
> ℹ️ 5. Type an Issue key. The issue you pick must have a valid Assignee.
> ℹ️ 6. Click on `Test`
> ℹ️ 7. The following result is displayed:> Macro (inline-media-image)
> ℹ️ 8. For the same script, select an issue which is unassigned and test the result (Repeat steps 4,5 and 6). Since the issue is unassigned, a null pointer exception occurs.
> ℹ️ 
> ℹ️ ![image](media://3cbbdc26-8a6a-4fce-8f7c-5d4d1205c027)

#### <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>](#GroovyscripttesterinJMWE-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 testing the script against an issue that is unassigned:</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"> using</span><span style="color: #000000"> the safe navigation operator ? that avoids the null pointer exception.</span>
- **<span style="color: #000000">Retest the script,</span>**<span style="color: #000000"> as </span>[<span style="color: #000000">explained above</span>](#GroovyscripttesterinJMWE-Te)<span style="color: #000000"> and verify the result in the script test panel. T</span><span style="color: #000000">he result value will be null</span>  
> 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, 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">Consider the following script,</span>

```
return (issue.get("assignee")? == "Scharlie")
```

- **<span style="color: #000000">Test the script,</span>**<span style="color: #000000"> against an issue assigned to a user </span>`Scharlie. `<span style="color: #000000">The script test would evaluate to </span>`false`<span style="color: #000000">.</span>  
> Macro (inline-media-image)
- **<span style="color: #000000">Identify the problem,</span>**<span style="color: #000000"> using the log variable (as shown below) and check what values are being compared. </span>
  <span style="color: #000000">Retest the script</span>**, **<span style="color: #000000">as </span>[<span style="color: #000000">explained above</span>](#GroovyscripttesterinJMWE-Te)<span style="color: #000000"> and verify the result in the script test panel. </span>

![image](media://9d4bffa0-efb8-4d7e-8a08-337629882c21)

<span style="color: #000000">The script is comparing a user object to a String value.</span>

- **<span style="color: #000000">Correct the problem, </span>**<span style="color: #000000">by fetching the username and then comparing the values</span>

- **<span style="color: #000000">Retest the script, </span>**<span style="color: #000000">as </span>[<span style="color: #000000">explained above</span>](#GroovyscripttesterinJMWE-Te)<span style="color: #000000"> and verify the result in the script test panel. </span><span style="color: #000000">Now the condition evaluates to true.</span>  
> 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 post-function is executed.</span>


> Macro (__confluenceADFMigrationUnsupportedContentInternalExtension__)