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

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

250 views 0 6
Read article

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