Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Groovy Script NPE error when updating multi-user custom field in a post function

I have the below script to update a multi-user custom field in a post function.

import com.atlassian.jira.user.ApplicationUsers

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue

IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = issueManager.getIssueObject(;
def subTasks = issue.getSubTaskObjects()
List<ApplicationUser> users;
CustomField multiUser = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("CC List")

subTasks.each {
String assignee1 = it.assigneeId
if(users == null)
users = new ArrayList<>();

issue.setCustomFieldValue(multiUser, users);
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)

The field gets updated in the issue after adding the last line, but also seeing the below error in the logs.

2019-02-09 13:43:59,780 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-02-09 13:43:59,781 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FA-635, actionId: 51, file: <inline script>
	at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(
	at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(
	at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(
	at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(
	at com.atlassian.jira.issue.IssueManager$updateIssue$ Source)

Could someone help resolve the issue?

1 answer

1 accepted

Hi @Atlassian Admin _Zynga_ ,

You could use something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

CustomField multiUser = customFieldManager.getCustomFieldObjectByName("CC List")
ArrayList<ApplicationUser> users = []

issue.getSubTaskObjects()?.each {
if (it.getAssignee()) users.add(it.getAssignee())

if (users) {
issue.setCustomFieldValue(multiUser, users)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

Thanks @Alejandro Suárez _Tecnofor_ . This script worked fine without any errors. Could you please clarify on the issue with the original script?

Sure, the initial problem with your code is that you are getting those exceptions because in some subtasks the assignee field is null. You have to check that field if you dont want to log null exceptions. 

And you complex more than necesary your code, for example, you are cheking if the users variable is null when it allways will be null, and you are using a method from userManager to get an ApplicationUser, when issue.getAssignee() method gives you an ApplicationUser itself.


Suggest an answer

Log in or Sign up to answer
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

81 views 0 4
Read article

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