I'm trying to assign a newly created sub-task to a user group member via a post function that's supposed to trigger the sub-task creation.
I'm using the "Create a sub-task" post function from ScriptRunner.
The problem is that the assignee that I set in the script doesn't get applied to the created sub-task. It, instead, gets assigned to the project lead - the default assignee.
Here is the script:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
def groupManager = ComponentAccessor.getGroupManager()
def group = "TS Lead"
def user = groupManager.getUsersInGroup(group)?.get(0).getKey()
log.debug "user: "+user
if (! user) {
log.warn ("Could not retrieve user from the "+group+" role")
return
}
issue.assigneeId = user
According to multiple sources on this Q&A forum,
issue.assigneeId = user
is the correct way to set the assignee. This makes the problem even more confusing.
I also tried moving the post function to the top and bottom of the post function queue for the transition, but it didn't make a difference.
I've printed to log the issue and assignee at the end of the script, and the values appear correct. This leads me to believe that the issue or its fields aren't being saved.
I've used a similar script in a post function to assign a user group user to the current issue, rather than a new issue, and that worked fine.
I'm using JIRA 7.1.9 and ScriptRunner is version 5.1.6.
Any ideas on how to solve this?
What do you mean by the new issue? Do you mean that you get an issue in your post function and change the assignee field for it? If so, then it is correct that your values are not saved.
Or you mean that this post function is on the create transition? Then you should put your post function last in the list and add the issue.store() function to the end of your script.
Post functions can change values in the same issue or they can create a "new issue", such as in the case of the "Create a sub-task" post function from ScriptRunner, and make changes to that new issue before it gets created. How do I save the custom assignee value for the about-to-be-created sub-task from a post function of the parent issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You want to say that you use the Create a sub-task post function and add this line into the Additional Issue Actions. Try to use
Issue.setCustomFieldValue(CustomField customField, Object value)
after the issue.assigneeId = user line.
You can find more info here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not trying to set any custom fields. Only the assignee system field. I don't see any mention of the assignee field in your article. Are you trying to say that system fields won't get saved unless a custom field has been set as well?
issue.assigneeId = user
isn't working. I feel like I need to save the issue object after that line, but that may not make sense since the creation of the issue happens, presumably, after that line already.
The MutableIssue function of "setAssigneeId(String assigneeId)" also doesn't seem to save the set assignee.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It does not matter what you set - a custom field or the assignee field or the reporter field. You still need to make the data appear in the indexes. And in order to do it you need to execute certain functions. The order of the post functions does not have any influence on the sub-task, because all the functions in your post functions work with the parent issue. That is why either the Adaptivist made it for you or you make it yourself. You can see from your experiments, that just setting the assignee field does not work, which means you have to call something to make the data appear in the indexes. There are three ways to do it and I provided you with the article, where I explain how to do it and what is the difference.
I believe, that you think that you set the assignee field for the sub-task, when the sub-task does not exist. But you can not be sure in it. Only Adaptivist knows. That is why I asked you to try to put data into indexes yourself.
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.