How to assigne an issue to user using scriptrunner

how can I assigne an issue to a specific user using add-on scriptrunner ?

i want to assigne an issue to user IN Database or on an custom field 

thank you

1 answer

It depends a little on which kind of script you want to do it in (Post function, behaviour, etc.), but it should be as simple as

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.userManager
def someUser = userManager.getUserByKey("someone")
issue.assignee = someUser

to get a specific user from the DB. If you want to get the user from a user-picker custom field, you'd do something like

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("My User Picker")
def someUser = issue.getCustomFieldValue(cf)
issue.assignee = someUser

Again, if you can provide some detail about when you want the custom field to be set (i.e. as part of a workflow, or automatically on the issue's create/edit screen), I could provide some more specific guidance.

I want to assign a issue to a user from the database so that it validates or rejects it using the add on scriptrunner it is possible? If yes . how can i do it and thanks

I'm afraid I still don't quite understand.

Do you mean you want this done as part of a workflow transition? If so, you probably want to use a workflow function, most likely a validator.

Perhaps it would help if you described in detail the behaviour you want from JIRA?

I want to do a similar workflow:
Create issue ==> approved by manager ===> apporved by manager ===> assigned ===> in progress => resolved
I am acctually blocking the assignment of the issue to the manager so that he validates and then do the same with the manager.
NB: I have a table on my DB with the name od manager and manager

Really i do not understand you:
I do not know where to put the code I am beginner thank you to provide me even the simple details.

Thank you

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("supp")
def someUser = issue.getCustomFieldValue(cf)
issue.description = someUser
issue.setAssignee(someUser)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

21,983 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you