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:
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
Solution/Workaround
After some digging i changed ".getUserByKey()" to ".getUserByName()" and that appeared to work. Not sure why the .getUserByKey() doesn't work.
Online 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.