Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set assignee using scriptrunner Edited

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")

1 answer

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you