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

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

This widget could not be displayed.

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.

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

This widget could not be displayed.

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}")
}

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

257 views 5 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you