It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Assignee is Always Null

I am trying to write a script to update all child assignee's when an Epic or Story assignee is updated. The problem I am running into is I want to update assignee only when it is the same as what the old assignee was, or it is unassigned. However, when it is unassigned and I try to take displayName value of it to compare to old assignee, I get nullPointerException. So I tried to add

 if(issue.fields.assignee == null)

Before accessing displayName, but then none of the issues got through, even those WITH assignees on them. I then tried printing the issue.fields.assignee and it turns out even if there is an assignee and the sub-fields are populated it is still seen as null. Lastly, I tried to encompass it in a try-catch block, but then it throws the exception every time. If I only try to update fields that HAVE an assignee, it works without exceptions or anything. Below is the full code for the section...any advice would be great I have been stuck on this for some time.

 

if(issueSubTasks.size() > 0){

logger.info(issueSubTasks.size()+" subtasks detected, updating fields on subtasks")

for(issueSubTask in issueSubTasks){
//Update each sub-task only if assignee was the same as the old or is empty
if(issueSubTask.fields.assignee.displayName.equals(oldAssignee))
{
result = put('/rest/api/2/issue/'+issueSubTask.key)
.header('Content-Type', 'application/json')
.body([
fields:[
assignee: issue.fields.assignee
]
])
.asString()
logger.info("subtask updated: "+issueSubTask.key)
}
}
}  

Again, as long as there are no "unassigned' issues going in to this, it works fine. This was the base code before running in to the issue with unassigned, where I tried all the above changes, with no success. 

1 answer

Did you try ... issue.assignee .... ? (without the ".fields." ?)

issue.assignee does not exist

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

902 views 14 12
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you