Excerpt |
---|
This tutorial will guide you through writing simple and complex Groovy conditions. The result of a scripted condition is a boolean. It can be used either to control the execution of a post-function or availability of a transition or trigger of a transition. |
...
Table of Contents maxLevel 1
2.1
...
Writing a simple conditional statement
This section of the tutorial will teach you writing a simple condition to check the priority of an issue is Critical or Highest in the Groovy script tester on the JMWE administration pages.
...
Step 2 - Write the script in the editor
Write the following script in the editor.
Code Block language groovy linenumbers true if(issue.get("priority").getName() == "Critical" || issue.get("priority").getName() == "Highest"){ return true } else{ return false }
- Your script will look like this:(screenshot)
Step 3 - Test your script
- Click on
Test Groovy Script
. - Input the issue key
GIJ-1
- Click on
Test
- The following result will be displayed.
Step 4 - Simplify your script
You can simplify the script removing the if-else
and returning the result of the comparision, a Groovy truthy or falsy
- Go the editor
Replace the script to:
Code Block language groovy linenumbers true issue.get("priority").getName() == "Critical" || issue.get("priority").getName() == "Highest"
Step 5 - Retest your script
- Click on Test again.
- The following result will be displayed.
Use cases
The output of the code is a boolean value. You can use this script in any relevant context, such as, Assign the issue to the Project lead if the priority of the issue is Critical
or Highest
.
References
2.2
...
Writing a conditional statement comparing two objects
This section of the tutorial will teach guides you condition to compare through writing a condition that compares` two ApplicationUser
objects.
Writing the script
Step 1 - Navigate to the condition
- Go to the Administration icon and click on it.
- Go to Issues - > Workflows
- Locate the workflow Software Simplified Workflow for Project GIJ
- Edit it
- Click on transition Start Progress
- Go to the
Conditions
tab - Edit the first condition in the list.
Step 2 - Write the script in the condition
Write the following script in Value.
Code Block language groovy linenumbers true issue.get("assignee") == currentUser
- Your condition configuration should look like this:
Step 3 - Test your script
- Click on
Test Groovy Script
. - Input the issue key
GIJ-1
- Click on
Test
- The following result will be displayed.
- Click on
Update
and save the condition.
Use cases
The output of the code is a boolean Boolean. You can use this script in any other relevant context, such as
- Allow progress on an issue only if the issue is assigned to the logged in user
- Only allow the reporter of the issue should be able to close the issue
References
2.3
...
Writing multiple conditions using switch
This section of the tutorial will teach you writing a multiple conditions using nested if.the switch control structure
Writing the script
Step 1 - Navigate to the post-function
- Go to the Administration icon and click on it.
- Go to Issues - > Workflows
- Locate the workflow Software Simplified Workflow for Project GIJ
- Edit it
- Click on the Create transition
- Go to the Post-functions tab
- Edit the last post-function in the list.
Step 2 - Write the script in the post-function
Select Groovy expression as the Transition type.
Write the following script in Transition.
Code Block if (issulanguage groovy linenumbers true - Your script should look like this:
...