Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

assignee not setting properly with post-function

Christopher Mangum October 13, 2015

I'm working on a transition to automatically set the assignee for an issue based on one of our custom fields, and I'm running into a strange issue: while the history for the issue claims that the assignee has changed after the transition finishes, the actual assignee listed on the issue view remains Unassigned. The script in question follows:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField_name = customFieldManager.getCustomFieldObjectByName( "Marketing Team" );

def issueService = ComponentAccessor.getIssueService();
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

if (issue.getCustomFieldValue(customField_name).toString() == 'Affiliate') {
    def assigned_to = ComponentAccessor.getUserUtil().getUserByName('userone');
    def validateAssignResult = issueService.validateAssign(user, issue.id, assigned_to.getKey());
    issueService.assign(assigned_to, validateAssignResult);

} else if (issue.getCustomFieldValue(customField_name).toString() == 'DM: Ad Buy' || issue.getCustomFieldValue(customField_name).toString() == 'DM: Ad Sales') {
    def assigned_to = ComponentAccessor.getUserUtil().getUserByName('usertwo');
    def validateAssignResult = issueService.validateAssign(user, issue.id, assigned_to.getKey());
    issueService.assign(assigned_to, validateAssignResult);
}

 

Having been over every related question I could find:

  1. I've tried this both as an inline script and running from file
  2. I've tried using mutableIssue.setAssignee() and mutableIssue.setAssigneeId() as alternatives
  3. I've verified the script is listed as the first item to run in the transition, and also confirmed that updating the change history and re-indexing are both listed as well in the transition steps 
  4. Just to stupid-check, I manually set the assignee to the two options listed, to make sure those users did have proper permissions in the current project
  5. I even tried re-indexing the entire JIRA instance after running through the transition, to see if there was some bug in the 'do a re-index' step, but no luck.

So with all that said: does anyone have any idea at all what I may be missing to have this work?

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 13, 2015

This is the same as this question: https://answers.atlassian.com/questions/31661190

You said you've tried it, but can you retry it, then if it doesn't work post the new code?

Dmitriy Kalabin July 16, 2017

Please help....i have script, script is first post function

The assigned user is displayed in the assign field after the transition, but it is not active-is displayed with a "?"

 

from com.atlassian.jira.component import ComponentAccessor
from com.atlassian.jira.issue import CustomFieldManager
from com.atlassian.crowd.embedded.api import User
from com.atlassian.jira.issue import Issue
from com.atlassian.jira.issue import MutableIssue
from com.atlassian.jira.issue import IssueManager
from com.atlassian.jira.security.groups import GroupManager
from com.atlassian.jira.security.roles.actor import UserRoleActorFactory

issueManager = ComponentAccessor.getIssueManager()
customFieldManager = ComponentAccessor.getCustomFieldManager()
customField = customFieldManager.getCustomFieldObject("customfield_10100")
Is1 = issue.getCustomFieldValue(customField).getValue()

Ur_dit = ComponentAccessor.getGroupManager().getUserNamesInGroup("K2_ABIS")

issue.setAssigneeId('Kur2')

 

 

 

Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 19, 2017

@Dmitriy Kalabin what plugin are you using to execute the above script?

0 votes
Christopher Mangum October 15, 2015

Well, moving the script to the bottom of the transition list didn't work...but using issue.setAssigneeId at the top did this time! The only difference I can see is that I was getting a mutableIssue object and using that to do the setting, rather than the direct call you listed in the other question. In any case,  I don't know how my searching never turned up the other question before, but that did the trick. Much appreciated.

TAGS
AUG Leaders

Atlassian Community Events