Hello Guys,
For tasks issue types in one of my project I need to assign issues to one particular user, how could I achieve that using scriptrunner ?
I don't want to use workflow post function for procedural reasons in the organization, we need to set assignee as an initializer at the create screen itself, so that its visible to the users as well.
Please suggest if anything,
Tried this but not working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName("username")
String userKey = user?.getKey()
Issue.setAssigneeId("userKey")
I don't want to use workflow post function for procedural reasons in the organization, we need to set assignee as an initializer at the create screen itself, so that its visible to the users as well.
Well, you say you want an initializer (presumably using Behaviours - https://scriptrunner.adaptavist.com/6.20.0/jira/behaviours-overview.html), but what you're pasting is Java API which you would in fact use in a workflow post-function.
To change the field value on the create screen so that people see it before actually creating the issue, please see the above link to learn a bit about Behaviours. There are then also tutorials and some examples to get the first one set up.
- basically need to create a behaviour and associate it with the project:issuetype mapping
- add below as initializer / server-side script
Something like this should work:
import com.atlassian.jira.component.ComponentAccessor import static com.atlassian.jira.issue.IssueFieldConstants.*
//This makes it only run for the Create Issue action only
if (getAction()?.id == 1) {
def assigneeField = getFieldById(ASSIGNEE)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("username") assigneeField.setFormValue(user.getKey())
}
Hello @Radek Dostál ,
I have tried this solution as well, at the create screen it shows me assignee set as JIRAUSERxxxxx but upon creation of issue, it is unassigned.
What should be the username ?, I have tried short id as well as full name of user but nothing working.
Thanks
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.