...
10. Getting all Sub-Tasks and Issue Key of the Sub-Task (Server)
Code Block | ||
---|---|---|
| ||
//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 | ||
---|---|---|
| ||
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:
Knowledge on how script-runner listener works for both cloud and server
Got to understand different scenarios for Jira based on which scripts were written
Basic knowledge on groovy
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
While setting the value for single select system fields we can directly give “values” instead of “id’s of values”
script-runner behaviors
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)
...