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 30 Next »

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.

On this page:

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.

Writing the script

Step 1 - Navigate to the Groovy script tester in the admin pages

  1. Go to the Administration icon  and click on it.
  2. Locate Add-ons from the menu and click on it.
  3. Locate JIRA MISC WORKFLOW EXTENSIONS on the left panel.
  4. Click on Groovy script tester.

Step 2 - Write the script in the editor

  1. Write the following script in the editor.

    if(issue.get("priority").getName() == "Critical" || issue.get("priority").getName() == "Highest"){
      return true
    }
    else{
      return false
    }
  2. Your script will look like this:

Step 3 - Test your script

  1. Click on Test Groovy Script.
  2. Input the issue key GIJ-3
  3. Click on Test
  4. 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 comparison, a Groovy truthy or falsy

  1. Go the editor
  2. Replace the script to:

    issue.get("priority").getName() == "Critical" || issue.get("priority").getName() == "Highest"

Step 5 - Retest your script

  1. Click on Test again.
  2. 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 only 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 guides you through writing a condition that compares` two ApplicationUser objects

Writing the script

Step 1 - Navigate to the condition

  1. Go to the Administration icon  and click on it.
  2. Go to Issues - > Workflows
  3. Locate the workflow GIJ: Process Management Workflow
  4. Edit it
  5. Click on transition Start Progress
  6. Go to the Conditions tab
  7. Edit the first condition in the list.

Step 2 - Write the script in the condition

  1. Write the following script in Value.

    issue.get("assignee") == currentUser
  2. Your configuration should look like this:

Step 3 - Test your script

  1. Click on Test Groovy Script.
  2. Input the issue key GIJ-3
  3. Click on Test
  4. The following result will be displayed.

Step 4 - Save the configuration

  1. Click on Update
  2. Publish the workflow.

Step 5 - Test it on an issue

  1. Go to the issue GIJ-5
  2. Check that the transition Start Progress is not available for a trigger on the issue GIJ-5.
  3. Click on Assign to me, to assign it to JCarter.
  4. Check that the transition Start Progress is now available for a trigger on the issue GIJ-5. 

Use cases

The output of the code is a Boolean. You can use this script in any 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 to close the issue

References

2.3 Writing multiple conditions using switch

This section of the tutorial will teach you writing multiple conditions using the switch control structure

Writing the script

Step 1 - Navigate to the post-function

  1. Go to the Administration icon  and click on it.
  2. Go to Issues - > Workflows
  3. Locate the workflow GIJ: Process Management Workflow
  4. Edit it
  5. Click on the Create transition
  6. Go to the Post-functions tab
  7. Edit the second post-function in the list.

Step 2 - Write the script in the post-function

  1. Select Groovy expression as the Transition type.

  2. Write the following script in Transition.

    def component = issue.getAsString("components")
    def priority = ""
    switch (component) {
     case "Finance" : priority = "Highest"; break
     case "Production Planning" || "Quality Management" : priority = "High"; break
     default : priority = "Medium"; break
    }
  3. Your script should look like this:

Step 3 - Test your script

  1. Click on Test Groovy Script.
  2. Input the issue key GIJ-5
  3. Click on Test
  4. The following result will be displayed.

Use cases

The output of the code is a String representing the priority of an issue. You can use this script in any relevant context, such as; Set the priority of the issue based on the Component

References

  • No labels