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.
Did you try ... issue.assignee .... ? (without the ".fields." ?)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.
Learn moreOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.