How to Set current assignee to "Unassigned" whenever group picker field is changed?

CMCSS Programmers April 11, 2017

I have a group picker field called "Assigned Team." Whenever someone changes the group in the group picker to any group, how can I automatically set the Assignee back to "Unassigned"? Not sure how to do this in either a Behaviour or Script Listener? Thank you.

2 answers

0 votes
Chris C May 15, 2018

Try this using a IssueInputParameters object.

import org.apache.log4j.Logger
import org.apache.log4j.Level

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue


IssueService issueService = ComponentAccessor.getComponent(IssueService);
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setAssigneeId(null)

def update = issueService.validateUpdate(user, issue.id, issueInputParameters)

log.debug "${issueInputParameters}"

if (update.isValid()) {
          issueService.update(user, update)
} else {
         log.debug("issue parameters are not valid: ${update}")
}

Kumar
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.
January 18, 2019

Hi @CMCSS Programmers @Chris C @Jason Huntowski @Ron Gates

For me also have same requirement i have group field called "Assignment Group" 

when ever the group field changes the assignee field have to change to "Unassigned" 

 

I have tried above scripts it did not worked for me I have added those scripts in "Script Listener" Custom Event "Issue Update" 

Can you please help me here how you guys achieved this

 

Thanks,

Kumar

0 votes
Ron Gates April 11, 2017

You can go with Custom Listener and configure it to trigger on "Issue Update" event (or any events combination of your choosing):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def currentIssue = event.issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def groupField = customFieldManager.getCustomFieldObjectByName('Group Field');
def groupFieldValue = currentIssue.getCustomFieldValue(groupField);

if (groupFieldValue != null) {
 currentIssue.setAssignee(null);
}

Note that ScriptRunner inline script syntax checker can see an error in the line that sets assignee but script will work fine without errors.

Jason Huntowski September 21, 2017

Hey Ron,

 

I have a similar need but your response is not working. I pasted my code below. My situation is that I am using a global listener to clear the assignee field if a custom field changes. I know my change code works, cause I use it for changing priority based on the change. But I can't get the assignee to null out.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Assignment Group"}

def currentIssue = event.issue;

if(change)
{
currentIssue.setAssigneeId(null);
return true
}
else return false

 any help you could give would be much appreciated.

Thanks,

Jason

Like Rajaravikiran S likes this

Suggest an answer

Log in or Sign up to answer