Change the assign on a post-function to a project role mumber

Mahdi Challouf December 10, 2019

The Task is on creating issue assign to one of a project roles based on the reporter.

I test this script below in a script console with a given issue I work fine but when I put it in a post-function is not working the assignee did not change.

Can someone help me, this is the code 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
//import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.RoleActor

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//def issue = issueManager.getIssueObject("BDI-5")

ProjectRoleManager projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager.class) as ProjectRoleManager
def groupManager = ComponentAccessor.getGroupManager()

// Get any role
ProjectRole PMOR = projectRoleManager.getProjectRole("Administrators")
ProjectRoleActors PMOActors = projectRoleManager.getProjectRoleActors(PMOR, issue.getProjectObject())
def PMOAssignee = PMOActors.getUsers().toList().first().username

log.warn(issue.getReporter())
log.warn("to see "+PMOAssignee)

if(groupManager.isUserInGroup(issue.reporter?.name, "jira-administrators"))
{
log.warn("true")
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def validateAssignResult = issueService.validateAssign(user, issue.id, PMOAssignee)
log.warn(issue.reporterId)
issueService.assign(user, validateAssignResult)
log.warn("here")
}

1 answer

1 accepted

0 votes
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2019

can you show the order of your postfunctions? 

it works finicky on creation iirc, might be you are assigning the issue, and then it applies default rule

so maybe try moving it to the very end of postfunctions list

Mahdi Challouf December 10, 2019

Hey IIya, 

I changed the post-function to different order still the same, no error found the script working but the assignee did not change, it seems like in post-function he didn't get the current issue I tried also to add this line in the end "issue.store()" still have the same   

Mahdi Challouf December 10, 2019

post-function 1.PNGpost-function 2.PNG

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2019

wait, that's no "creating issue"

for regular transition you can just use 

issue.assignee = PMOAssignee

it works because before the issue is stored to database postfunctions are performed on Mutable Issue

Mahdi Challouf December 10, 2019

the issue is alredy created.

Yeah it's

issue.assigneeId = PMOAssignee
issue.assignee //should take a string 

 Thank you IIlya for you help it works :)

Suggest an answer

Log in or Sign up to answer