Hi!
Could you please assist me with the script for routing specific issue type (during the Create transition) to a group or role? Is this possible? Is there an alternative solution?
Requirements:
when:
Project = Net
Issuetype = Task
route issues to:
Group or Role = developers
Appreciate any help.
Regards,
Daniel
Could you please clarify what do you mean by "route issues to"?
Hi Ivan,
When creating a ticket, from the issue type drop-down, the issue type 'Task' should only be available to users from the group/role 'developers'.
That's the requirement.
Or maybe if not possible to hide it from everyone else, only let proceed and create issues the users that belong to that group/role. The others would get an error message or something.
Let me know.
Thanks,
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
Cheers for the clarification. I see two options here:
1) Create a scripted validator on the 'Create issue' screen, that will check if the current user belongs to either 'Developers' group or 'Developers' project role. If he doesn't then the issue won't be created and an error message will be displayed.
2) Configure issue security first. Then create a scripted post function that will set a proper security level for all issues which belong to a certain issue type. That way anyone can create then but only select users/groups will be able to see them.
So it's up to you which approach suits your requirement the best.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the ideas Ivan.
I have a custom script that I shall be adapting to my needs and will set it as a validator. I believe that's the most straight-forward solution for me.
Will let you know in case something changes.
Have a good day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you need help with your script I might be able to help, so feel free to let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes please.
I got the below script working for groups however, I need the same for project role instead. The reason is that I want to give the project lead autonomy to add/remove users that can create Tasks.
Do you think you can help me to tweak this script to work with roles? Or maybe you have a different script...
Thank you.
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def groupManager = ComponentAccessor.groupManager
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
if(issue.issueType.name == 'Task'){
if(!groupManager.isUserInGroup(user, 'developers')){
throw new InvalidInputException("issueType",
"Tasks can only be created by Developers")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.security.roles.ProjectRoleManager
def roleMgr = ComponentAccessor.getComponent(ProjectRoleManager)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def role = roleMgr.getProjectRole("role name")
if(issue.issueType.name == 'Task'){
if(roleMgr.isUserInProjectRole(currentUser, role, issue.getProjectObject() == false){
throw new InvalidInputException("issueType",
"Tasks can only be created by Developers")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting the below error. There was also a missing closing parentheses in the original script. The screen shot below already has that fixed.
Let me know. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed, I missed a closing parenthesis! It should be like this:
if(roleMgr.isUserInProjectRole(currentUser, role, issue.getProjectObject()) == false)
Other than that I believe you are facing a common ScriptRunner issue with static type checking not always being accurate. More info here. So I guess you can simply ignore it in this very case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got this working now. It was really the lack of parentheses that was throwing everything off.
Thanks very much for your support on this Ivan.
Have a good day!
As a reference for others in a similar case, here's the final script:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.security.roles.ProjectRoleManager
def roleMgr = ComponentAccessor.getComponent(ProjectRoleManager)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def role = roleMgr.getProjectRole("NET - Developers")
if(issue.issueType.name == 'Task'){
if(roleMgr.isUserInProjectRole(currentUser, role, issue.getProjectObject()) == false){
throw new InvalidInputException("issueType",
"Tasks can only be created by Developers")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great news! Glad I could help. Please mark this solution as "Accepted" if it resolved your issue.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.