Our new Appfire Documentation Space is now live!

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

Groovy in JMWE

JMWE provides a wide array of easy to use workflow extensions to create advanced workflows. However, some advanced customization will require using scripting to further configure these extensions, such as:

  • Auto-assign the issue to a user based on the request type
  • Unlink issues of the current issue only when the issue has been rejected
  • Notify the user with a probable date of resolution for the issue through a comment

Writing a Groovy script in JMWE

A Groovy editor is provided in all the applicable workflow extension configuration screens and the JMWE administration page 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. JMWE 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 trigger the transition and/or look at the Jira logs to see the outcome.

Writing a Groovy script: In the workflow extension configuration, select Groovy expression or Groovy template as the Value type (when available). 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, as well as a linked issue, when applicable. 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 JMWE you will be using the Groovy language and Jira APIs augmented by JMWE. 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. JMWE 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 access the current user, you can use the currentUser global variable.

currentUser

To access the linked issue being processed (e.g. in a Comment Linked Issues post-function), you can use the linkedIssue variable. Note that it is only applicable to workflow extensions that operate on linked issues.

linkedIssue.assignee

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

JMWE has some more variables and global functions that are exposed to your Groovy scripts.