Hi Team,
I want to copy Assignee value to Testers field only if the Assignee is a QA User project role using groovy script.
Can someone help me.
Thanks in advance
Hi Teju,
Here's how you do it. I'm going to assume that your 'Testers' field type is a single user picker and its ID is 11111:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
ProjectRoleManager roleMgr = ComponentAccessor.getComponent(ProjectRoleManager)
ProjectRole qaUserRole = roleMgr.getProjectRole("QA User")
CustomField testers = ComponentAccessor.getCustomFieldManager().getCustomFieldObject((Long) 11111)
if (roleMgr.isUserInProjectRole(issue.getAssignee(), qaUserRole, issue.getProjectObject())){
issue.setCustomFieldValue(testers, issue.getAssignee())
}
Yes it worked. but the Testers field is multi user picker and need to append users not to override. How to do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's easy.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.user.ApplicationUser
ProjectRoleManager roleMgr = ComponentAccessor.getComponent(ProjectRoleManager)
ProjectRole qaUserRole = roleMgr.getProjectRole("QA User")
CustomField testers = ComponentAccessor.getCustomFieldManager().getCustomFieldObject((Long) 11111)
if (roleMgr.isUserInProjectRole(issue.getAssignee(), qaUserRole, issue.getProjectObject())){
ArrayList<ApplicationUser> testerList = issue.getCustomFieldValue(testers)
if (!testerList.contains(issue.getAssignee()){
testerList.add(issue.getAssignee())
issue.setCustomFieldValue(testers, testerList)
}
}
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 can pretty much ignore this error, the code should still work. Static type checking in Scriptrunner is not always accurate. Oh and looking at your screenshot, don't forget to change 11111 to an actual ID of your field.
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.