Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version

IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
Issue updatedIssue = event.getIssue()
log.error "Issue is: " + updatedIssue
Collection<Version> fixVersions = new ArrayList<Version>()
fixVersions = updatedIssue.getFixVersions()
log.error "Fix versions of parent are: " + fixVersions
Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
log.error "Sub tasks are: " + subTasks
subTasks.each {
    log.error "Type : " + it.issueType.getName()
    if(it.issueType.getName() == "Migration") {      
    if (it instanceof MutableIssue) {
        ((MutableIssue) it).setFixVersions(fixVersions)
        issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)
        log.error "Fix version of subbtask"
    }
   }
}

4. Script to set a default value for fixVersion field (Server)

Code Block
languagegroovy
def versionIdProductionMaintenance = "10214"
def versionIdProductionUAT = "10306"
def actionName = "Create"

if (getActionName() != actionName) {
    return // not the initial action, so don't set default values
} 
//get fixVersion ID
def fixVersionsField = getFieldById("fixVersions")
//set fixVersion value
def fixVersionsNewValue = fixVersionsField.setFormValue([versionIdProductionMaintenance, versionIdProductionUAT])

Learning:

  1. Knowledge on how scriptrunner listener works for both cloud and server

  2. Got to understand different scenarios for Jira based on which scripts were writtenBasic knowledge on groovy for Jira based on which scripts were written

  3. Basic knowledge on groovy

  4. While setting the value for multi-select fields always set the values based on “id’s of values” and not “values itself“ in behaviors

  5. While setting the value for single select fields we can directly give “values” instead of “id’s of values”

  6. scriptrunner behaviors

No

Date

Topics learnt

1

12-03-2020

Introduction to Groovy, how groovy works, static and dynamic compilation, optional typed, how to use scriptrunner to execute scripts in script console, how to look up to javadoc for methods and classes

2

13-03-2020

Variables, rules, operators, built in scripts and scenarios in scriptrunner, listeners, exception handling,

how to get all the details related to a specific issue (code)

3

16-03-2020

Conditional statements (if else, switch), looping (for, for in, while), String, string functions, interpolation, multilines, methods / functions, closures, how to get all the subtasks related to issues, fetch their data and manipulate their information (code)

4

17-03-2020

Worked on setting a default value to a fix version system field (includes reading and understanding the behaviors of scriptrunner, sample examples, and implementation of the code)