Versions Compared

Key

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

...

10. Getting all Sub-Tasks and Issue Key of the Sub-Task (Server)

Code Block
languagegroovy
//import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject("ANDROID-38");

def output = ""
for (e in issue.getSubTaskObjects()) {
    
	output = output + e.getSummary()  +"," + e.issueType.name + "<br/>"
    
}

return output
// Uncomment this line for getting issue key of the subtask
//MutableIssue sub_issue = im.getIssueObject(issue.getSubTaskObjects()[0].toString());

//return sub_issue

11. Script to hide the fields on create screen if the user is not a project admin (Server)

Code Block
languagegroovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager  
import com.atlassian.jira.security.roles.ProjectRole

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def isAdmin = false
def projectManagerClass = ComponentAccessor.projectManager
def projects = projectManagerClass.getProjects()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def cityField = getFieldByName("City")
def brandField = getFieldByName("Preferred Brand")

projects.each{
    def projectRoles = projectRoleManager.getProjectRoles(loggedInUser, it)
    if(projectRoles.find(){it.getName() == "Administrators"}){
        isAdmin = true     
    }
}

if(isAdmin.equals(true)) {
cityField.setHidden(false)
brandField.setHidden(false)
} else {
cityField.setHidden(true)
brandField.setHidden(true)
}

Learning:

  1. Knowledge on how script-runner listener works for both cloud and server

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

  3. Basic knowledge on groovy

  4. While setting the value for multi-select system 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 system fields we can directly give “values” instead of “id’s of values”

  6. script-runner behaviors

  7. While setting the value for single select custom field we have to give “id’s of values” only (can also be directly configured in field setting as these are custom fields)

...