You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hello and happy new year.
I am having an issue with doing issue assignments via IssueService.assign(ApplicationUser, IssueService.AssignValidationResult) using ScriptRunner via the Java API. Note that when I show my code, I have attempted to isolate this issue by creating a new project and doing some trivial assigns. This is not my actual production code but just an example extract.
This project is named DEMO and it’s a simple workflow just consisting of the statuses To Do and Done, with a single transition called Done. Both the create transition and the Done transition have the same workflow to set the assignee to the reporter:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def issueService = ComponentAccessor.getIssueService()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getUserManager().getUserByName("mishelpdesk")
def reporter = issue.getReporter().getName()
def validateAssignToReporterResult = issueService.validateAssign(user, issue.id, reporter)
if (validateAssignToReporterResult.isValid()) {
issueService.assign(user, validateAssignToReporterResult)
}
In both cases, this script post-function is set as the last post-function in the transition. Here is what happens when I create a ticket with myself as the reporter, and then change the reporter back to the user mishelpdesk
Notice that in the issue history, the ticket is reassigned to mishelpdesk, but this does not persist or actually take place. However, if I execute the same function in the script console as opposed to the workflow, it works as intended.
Any idea why this would work in the create transition but not subsequent ones?
Hi @Adam L ,
Happy 2021!
I didn't spot any obvious issue in your script.
It looks like the assignee is changed in the issue history but for some reason the re-index didn't happen for this issue.
Also, can you try the below script in your post-function? It's important that this script is placed before the re-index step instead of being on the last step as you did with your script.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def username = "mishelpdesk";
def user = ComponentAccessor.getUserManager().getUserByName(username)
issue.setAssignee(user)
I didn't have the chance to test it, but I adapted this code from this script: https://library.adaptavist.com/entity/round-robin-assign-issue-to-users-in-a-certain-project-role
I was trying deliberately to avoid issue.setAssignee() because I thought the only way to persist it was to use issue.store(), which is deprecated. However, I looked at the API and saw you could do this using issueManager().updateIssue(), where it works. This is an acceptable workaround but I am still curious why this issue exists for issueService. I'd like to keep it open for a couple days to see if there are any more insights.
Below is a short snippet of code I used:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getUserManager().getUserByName("mishelpdesk")
def reporter = issue.getReporter()
issue.setAssignee(reporter)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_ASSIGNED, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope someone from community can explain why IssueService didn't work :)
I do agree with you, issue.store() must be avoided since there are known issues about this
I think if you place this code in the first position of the post-functions, you won't need to use issueManager.updateIssue(), my assumption is that Scriptrunner will modify the MutableIssue on runtime and pass the modified issue to the next post-function.
Can you try your script without the last line in the first post-function position and see if that works?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, this worked for me, thanks! Before I created this ticket I tried adjusting the order and it did not fix via the IssueService method but it does when you call setAssignee on MutableIssue. I will mark this as the accepted answer for now but I am still curious why this is happening.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.