Hello!
I have a post-function which should add a user to a project role, depending on value of custom field selected.
I created a script based on samples which I found here on the Atlassian answers.
My script is working but only with one condition: if I define the user name directly in the script:
def actors = ['lsmith']
but I need script to work with current user, without defining their username in a code. So that the current user will be added to selected project role.
I tried this:
def user = (ApplicationUser) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("test_mav_user_picker").getValue(issue)and then:
projectRoleService.addActorsToProjectRole(currentUser,
projectRole1,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
but this does not work and show an error: "Cannot find matching method"
Please help to understand how can I add a current user to a project role in a post-function?
here is the full script:
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import groovy.transform.Field
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.user.ApplicationUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManager = ComponentAccessor.getProjectManager()
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def errorCollection = new SimpleErrorCollection()
//name of the custom field
def customFieldName = 'Notification type'
//get the custom field object
def customFieldObject = customFieldManager.getCustomFieldObjectByName(customFieldName)
Issue issue = issue
def customFieldValues = customFieldObject.getValue(issue)
def user = (ApplicationUser) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("test_mav_user_picker").getValue(issue)
def project = projectManager.getProjectObjByKey("ATL")
def actors = ['lsmith']
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
customFieldValues.each { LazyLoadedOption it ->
def optionValue = it.getValue()
switch (optionValue){
case "Comments":
def projectRole = projectRoleManager.getProjectRole("Comments")
projectRoleService.addActorsToProjectRole(actors,
projectRole1,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
break
case "Transition":
def projectRole1 = projectRoleManager.getProjectRole("Transition")
projectRoleService.addActorsToProjectRole(actors,
projectRole1,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
break
case "Issue Update":
def projectRole2 = projectRoleManager.getProjectRole("Issue Update")
projectRoleService.addActorsToProjectRole(actors,
projectRole2,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
break
case "Issue resolved":
def projectRole3 = projectRoleManager.getProjectRole("Issue resolved")
projectRoleService.addActorsToProjectRole(actors,
projectRole3,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
break
}
}
Danielle,
In the Kanban board the issues are always added in the Backlog however you can write a JQL and save it as a filter to exclude some of the issues, then use that filter to populate your board.
-Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.