I have spent all weekend trying different solutions proposed here for my issue. I have not had success. Please help. The code that I get to work does not seem to be adding an actual user from the directory. The entries appear to be string only. I execute this code in the Additional Issue actions section of the create Sub-Task script during the create issue transition of the parent issue.
My code is below.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Direct Manager'}
java.lang.String user22 = sourceIssue.getCustomFieldValue(cf)
issue.setAssigneeId(user22)
Please try this code (ignore any compile time warning)
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Direct Manager'}
issue.setAssigneeId(sourceIssue.getCustomFieldValue(cf).getKey())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more thing Tarun.... Now I have to add a specific user that I can hard code in for other subtask. Any suggestions on this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.userManager
def userKey = userManager.getUserByName("<insert your username>").getKey()
issue.setAssigneeId(userKey)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Tarun,
The script failed. Here is my code and the error message below.
Code:
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.userManager
def userKey = userManager.getUserByName("Paul Gomez").getKey()
issue.setAssigneeId(userKey)
Error Log
2018-06-18 09:35:55,612 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-06-18 09:35:55,613 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: NOP-195, actionId: 1, file: null java.lang.NullPointerException: Cannot invoke method getKey() on null object at Script443.run(Script443.groovy:4)
Am I not entering the user name correctly? Should I enter the full name with the email?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it!!! I needed to enter the user name in this format: first.last
Great work Tarun!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.