Hi folks,
Here is what I am trying to accomplish. I am trying to somehow display a list of selected JIRA projects and the user-roles of those project on a JIRA dashboard. I have looked into this and I couldn't find any dashboard gadget that could give me that. I think the only way I can get this information is by writing groovy script which I am not good at :( . I was wondering if anyone could help me write a groovy script so that I could display the list I am asking for. I don't mind have a scripted field to show that information in a JIRA issue. I could create a story or task for each of those project and list those stories on the dashboard which would show that scripted field.
I honestly don't care about how it should look but here is an example what I am trying to accomplish. I will also attach a screenshot.
Project | Developers | Scrum Master | Product Owner |
Project A | Tom, Adam, Julia | Robert | Lew |
Project B | Cynthia, Melissa, Jared | John | Terri |
Project C |
|
|
|
|
|
|
|
Thank you so much!
- Shahriar
Thank you so much!
- Shahriar
Hi @Shahriar ,
That looked fun so I gave it a try, here is a script to display this table in the issue description using behaviours. So of course you would have to adapt it to display it in a appropriate way/place (not sure about that).
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.ComponentManager
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def desc = getFieldById("description")
String table = "||Project||"
def projects = ["A","B", "C"]
def projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def projectRoles = projectRoleManager.getProjectRoles()
projectRoles.each {
table += it.getName() + "||"
}
projects.each {
def project = ComponentAccessor.getProjectManager().getProjectObjByKey(it)
table += "\n||" + it + "|"
projectRoles.each {
def actors = projectRoleManager.getProjectRoleActors(it, project).getUsers().collect {
it.getDisplayName()
}
table += (actors.size() == 0?" ":actors.join(",")) + "|"
}
}
desc.setFormValue(table)
Antoine
Hi Antoine,
Man you are freaking genius!
I used your script but for some reason it gives me the data for all projects instead of just those three, for e.g. A, B and C.
FYI - I believe the following class has been depreciated in the newer version of JIRA. It keeps giving error.
import com.atlassian.jira.ComponentManager
So I had to remove that and also had to make this change:
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class) as ProjectRoleManager
Thank you so much for your help, Sir!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shahriar Kabir ,
I wish I were a genius! :)
Regarding your questions :
Good job seeing that deprecation, I am working on 7.6.0, so I will keep an eye on that when I upgrade. :)
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.security.roles.ProjectRoleManager
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def desc = getFieldById("description")
String table = "||Project||"
def projects = ["A","B", "C"]
def roles = ["Administrators","Developers"]
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class) as ProjectRoleManager
def projectRoles = projectRoleManager.getProjectRoles().findAll{ it.getName() in roles }
projectRoles.each {
table += it.getName() + "||"
}
projects.each {
def project = ComponentAccessor.getProjectManager().getProjectObjByKey(it)
table += "\n||" + it + "|"
projectRoles.each {
def actors = projectRoleManager.getProjectRoleActors(it, project).getUsers().collect {
it.getDisplayName()
}
table += (actors.size() == 0?" ":actors.join(",")) + "|"
}
}
desc.setFormValue(table)
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
Thank you again so much. I will try the updated script you sent. Thank you!
- Shahriar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're welcome ! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.