Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Error Passing Values into Multiuser field

Ryan L
Contributor
March 11, 2019

I recently adding a few scripts that will add a certain set of user to an Custom Approvers field when an issue was transitioned. It worked for a while but all of a sudden it started to throw up errors and wouldn't transition

Here is the post function Script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def cf2 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Escalation Approvers'}
issue.setCustomFieldValue(cf2, null);
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Escalation Approvers'}

List<ApplicationUser> userList = new ArrayList<>()
userList.add(userManager.getUserByKey("userA"))
userList.add(userManager.getUserByKey("userB"))
userList.add(userManager.getUserByKey("userC"))
userList.add(userManager.getUserByKey("userD"))
userList.add(userManager.getUserByKey("userE"))
userList.add(userManager.getUserByKey("userF"))
issue.setCustomFieldValue(cf, userList);

These are the Pre-2000 AD/LDAP ID of the users and is what shows up as the Username for the user. 

It worked all throughout testing and this morning but not to long after it stopped working and decided that  the following line is the problem. If i comment it out it works

userList.add(userManager.getUserByKey("userE"))

Steps Taken:

  • I tried moving the script to different spots on the post function but if I move it beyond spot 4(Update change history for an issue and store the issue in the database.) nothing happens at all with it and no one shows up in the Escalation Approvers field 
  • verified I can add the ID manually to the field in the ticket
  • removed and retyped the line
  • change the position of the line in the script
  • verified user account is not locked, expired or anything else wrong with it

When i check the logs i find this

2019-03-11 12:17:42,805 http-nio-8080-exec-26 ERROR RL.ADM 737x2506870x4 xof9i 10.XXX.XXX.133 /secure/CommentAssignIssue.jspa [c.a.jira.workflow.OSWorkflowManager] Caught exception while attempting to perform action 521 from workflow 192310 on issue 'JSD-1234'
java.lang.NullPointerException
at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:123)
at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:80)
at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(ImmutableCustomField.java:376)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:411)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)

 

EDIT:

I tried a different script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def ApproversField = customFieldManager.getCustomFieldObjectByName("Escalation Approvers")

def Approvers = [] as List
Approvers << ComponentAccessor.getUserManager().getUserByKey("userA")
Approvers << ComponentAccessor.getUserManager().getUserByKey("userB")
Approvers << ComponentAccessor.getUserManager().getUserByKey("userC")
Approvers << ComponentAccessor.getUserManager().getUserByKey("userD")
Approvers << ComponentAccessor.getUserManager().getUserByKey("userE")
Approvers << ComponentAccessor.getUserManager().getUserByKey("userF")

Approvers = Approvers.unique()
ApproversField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(ApproversField), Approvers), new DefaultIssueChangeHolder())

But the issue still persists, with the NULL handler all but "userE" gets added to the field

 

Error message

2019-03-11 13:47:39,344 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-03-11 13:47:39,344 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: JSD-1234, actionId: 521, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:123)
	at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:80)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(ImmutableCustomField.java:376)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:411)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)
	at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)
	at Script586.run(Script586.groovy:17)

 

 

So with everything i checked, it had to be something about userE's profile that is causing the issue considering it's re-created via 2 different scripts

1 answer

0 votes
Ryan L
Contributor
March 11, 2019

Solution/Workaround

After some digging i changed ".getUserByKey()" to ".getUserByName()" and that appeared to work. Not sure why the .getUserByKey() doesn't work. 

 

Ref: https://docs.atlassian.com/software/jira/docs/api/7.1.1/com/atlassian/jira/user/util/UserManager.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events