I must be missing something in this simple script. It's a post function (not in the Create transition). The logs appear just as expected, the user in question can be assigned the issue via the UI, the custom field exists. But the assignee is never changed in the issue.
import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Category import com.atlassian.jira.issue.MutableIssue /** * The template script for setting the assignee from a custom user picker * Make sure the user chosen is assignable. */ def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction"); log.setLevel(org.apache.log4j.Level.DEBUG); def issueManager = ComponentAccessor.getIssueManager(); def customFieldManager = componentManager.getCustomFieldManager(); def cf = customFieldManager.getCustomFieldObjectByName("Source User"); if (cf == null) { log.error("No custom field found"); return; } def user = issue.getCustomFieldValue(cf); if (user != null) { def user2 = user.getDirectoryUser(); log.error("Setting assignee to: " + user2.getName()); log.error("Issue type : " + issue.getClass().getName()); MutableIssue mutableIssue = issueManager.getIssueObject(issue.id) mutableIssue.setAssignee(user2); mutableIssue.store(); }
I've also tried using
MutableIssue myIssue = issue
The script works fine. The problem was that the workflow I was testing it with had another post function lower down that set the assignee to the current user. I should take my own advice and stay away from the default JIRA workflows and the unexpected stuff that lurks in them :-)
:-)
I would stay with MutableIssue myIssue = issue, because otherwise you may get index problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can just reference "issue" without declaring it... I tend to use the construct Henning posted only because then you get typing help from the IDE.
Agree with not reloading the issue though... this will reload the issue from the db and disregard what the user just entered on the form - depending on the ordering of the post-functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Got it. I forgot that IssueImpl is already a MutableIssue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried above script and get below error. Please let me know how to resolve it and the proper syntax as I am new to Groovy.
2014-07-24 00:16:30,371 http-17000-14 ERROR ikkhan 16x14831x1 j02hwu 10.19.0.17,10.253.96.38 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.PostFunction] Issue type : com.atlassian.jira.issue.IssueImpl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No information there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to use the same script but I'm seeing this line gives an error
MutableIssue myIssue = issue
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script227.groovy: 29: unable to resolve class MutableIssue @ line 29, column 14. MutableIssue myIssue = issue
Anything obvious?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe you forgot to copy the import statements in the script? Regarding your error message the following line is missing
import com.atlassian.jira.issue.MutableIssue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this issue resolve ?.
Please post correct script for it, we are also facing same issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After much playing around we found existing functionality from "Assign From Field This function assigns issue to user from the custom field.". Part of the script runner, so no need for custom scripting
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.