Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

Groovy in JMCF

JMCF provides a 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:

  • Calculate and display the author of the last comment on the issue
  • 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

Groovy editor 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. 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 tool that lets you test your script against any issue. This allows you 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.

Writing a Groovy script: In the custom field configuration screen of calculated custom fields that use Groovy script, click on Edit Groovy expression or Edit Format expression, whichever is applicable. For example to write a script to access the key of an issue:

issue.key

Testing the Groovy script: After writing the Groovy script, click on Test Groovy ScriptA modal dialog window opens, asking you to pick an issue to run the Groovy script against. Select an issue key. Click on TestThe result of the script is displayed.

Accessing Jira objects from your Groovy script

An interface is a blueprint of a class. It has static constants and abstract methods. In JMCF you will be using the Groovy language and Jira APIs augmented by JMCF. The most common interface that you will be using in your scripts is the Issue interface. This API provides the methods you can use on any Issue 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 issue variable.

issue.get("summary")

To log information in your script for debugging purposes, you can use the 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 that are exposed to your Groovy scripts.