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

JMCF provides a <span style="color: #000000">suite of custom fields for use in your JIRA instance, of which some calculated custom field types use a script written in the Groovy language to calculate/format the field value, such as:</span>

- <span style="color: #404040">Calculate and display the author of the last comment on the issue</span>
- Calculate and display the time spent in the current status
- Calculate and display the user has last modified a field value

### Writing a Groovy script in JMCF

A [Groovy editor](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465600948) <span style="color: #000000">is provided in all the applicable custom field configuration screens to write your Groovy scripts. You can either write them directly in the built-in editor, or use any IDE and then copy them to the editor.</span> The built-in editor automatically indents your code, checks for syntax errors, colorizes keywords, comments, variables, and so on. JMCF includes a [Groovy script tester](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465764674) tool that lets you test your script against any issue. This allows you <span style="color: #000000">to debug your script and make changes without having to actually save the configuration, refresh the issue or perform a re-index and look at the field value on the Issue view screen to see the outcome.</span>

**<span style="color: #000000">Writing a Groovy script:</span>**<span style="color: #000000"> </span><span style="color: #000000">In the custom field configuration screen of calculated custom fields that use Groovy script, click on </span>`Edit Groovy expression`<span style="color: #000000"> or </span>`Edit Format expression,`<span style="color: #000000"> whichever is applicable. For example to write a script to access the key of an issue</span>**<span style="color: #000000">:</span>**

```groovy
issue.key
```

<span style="color: #000000">**Testing the Groovy script: **</span><span style="color: #000000">After writing the Groovy script, c</span><span style="color: #000000">lick on </span>`Test Groovy Script`<span style="color: #000000">. </span><span style="color: #000000">A modal dialog window opens, asking you to pick an issue to run the Groovy script against. Select an issue key. </span><span style="color: #000000">Click on </span>`Test`<span style="color: #000000">. </span><span style="color: #000000">The result of the script is displayed.</span>

![image](media://2610e37d-9e2b-4ea2-add5-65c47d07a179)

### Accessing Jira objects from your Groovy script

<span style="color: #000000">An interface </span><span style="color: #000000">is a blueprint of a class. It has static constants and abstract methods. </span><span style="color: #000000">In JMCF you will be using the Groovy language and </span>[<span style="color: #000000">Jira APIs augmented by JMCF</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465863009)<span style="color: #000000">. The most common interface that you will be using in your scripts is the </span>[<span style="color: #000000">Issue interface</span>](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465764748)<span style="color: #000000">. This API provides the methods you can use on any </span>`Issue`<span style="color: #000000"> object. JMCF also exposes global variables and functions to access contextual information in your script. For example, to access the issue being transitioned, you can use the global </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.</span>

```groovy
issue.get("summary")
```

To log information in your script for debugging purposes, you can use the [log](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465732169/Variables+and+functions+used+in+a+Groovy+script#log) global variable. You can use the WARN level to output information in the log as well as the tester result.

```
log.warn("Reporter set by the script is: " + newUser.name) //where newUser is a variable holding an ApplicationUser object
```

JMCF has [some more variables and global functions](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465732169) that are exposed to your Groovy scripts.