Hi there,
I am looking at ways of setting the assignee on a workflow post function. Firstly I have been testing this out using the script runner console with the following piece of code that I seen Stephen Cheesley posted here
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("tbas")
def issue = issueManager.getIssueObject("HW_TEST-64")
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)
However whenever I used this script in the console it sets the assignee to whoever the reporter is on that issue, no matter who I define it should be in the script.
Am I missing something obvious here?
came back to look at my old questions now I have been using Scriptrunner for a bit longer and have built up more experience.
The way to do this is the following:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("user")
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def assigneeUpdate = issue.setAssignee(user)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
validateAssign(ApplicationUser user, Long issueId, String assignee)
the reporter is set as id coz you explicitly set it to issue.reporterId.
use instead
def validateAssignResult = issueService.validateAssign(user, issue.id, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thankyou! school boy error it seems.
Although I've tried running it with your suggestion but it still doesn't set the Assignee to the user I set in the script and there are no errors when I try to run it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am still looking at doing this, just to give some more background.
my end goal is that I can copy a project including some issues over to a new project - this is working fine.
Now I want to be able to change the assignee of the copied issues to somebody who I stipulate in the script or choose from a custom field.
I have got the copy project working from a workflow post function but now need to be able to change the assignee, I was thinking within the same script would be best? unless there are other methods I am not thinking of?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all of the replies so far, I am still unable to change the assignee of an issue using scriptrunner console, any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
see-above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may want to do it this way base on a custom-field option-value(internal) on the create issue screen in this case.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomField cf86903 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_86903")
String cf86903Value = issue.getCustomFieldValue(cf86903)
if(cf86903Value == 'Internal') issue.setAssigneeId("groovy_m")
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.