Our new Appfire Documentation Space is now live!

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

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

JMCF provides a suite of custom fields for use in your JIRA instance, of which some calculated custom field types use a formula 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 formula in JMCF

Groovy editor is provided in all the applicable custom field configuration screens to write your Groovy formulae. 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 formula against any issue. This allows you to debug your formula 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 formula: In the custom field configuration screen of calculated custom fields that use Groovy formula, click on Edit Groovy expression or Edit Format expression, whichever is applicable. For example to write a formula to access the key of an issue:

issue.key

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

Accessing Jira objects from your Groovy formula

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 formulae 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 formula. For example, to access the issue being transitioned, you can use the global issue variable.

issue.get("summary")

To log information in your formula 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 formula 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 formulae.

  • No labels